DECLARE @input AS NVARCHAR(4000) 
DECLARE @pattern AS NVARCHAR(4000) 
  
SET @input = 'red,magenta,green' 
SET @pattern = '^((?<colour>.+?)(,|$))+$' 
  
  
-- matches if green in the input 
IF (dbo.RegexMatch(@input, '(G|g)reen') = 1) 
      SELECT 'green found in string' AS [Message] 
  
-- gets the number of captures in the named group colour 
SELECT dbo.RegexMatchGroupCaptureCount(@input, @pattern, 'colour') AS CaptureCount 
  
-- gets the value of capture at index 2 in the named group colour 
SELECT dbo.RegexMatchGroupAt(@input, @pattern, 'colour', 2) AS CaptureItem 
  
SELECT * FROM dbo.RegexMatchGroupCaptures(@input, @pattern, 'colour') 
  
SET @pattern = '^\s*|\s*$' 
  
-- performs a trim 
SELECT dbo.RegexReplace('  This should perform a trim  ', @pattern, '') AS Trimmed 
  
-- splits the input string on comma delimiter