Skip to content

Latest commit

 

History

History
20 lines (11 loc) · 962 Bytes

group-match.md

File metadata and controls

20 lines (11 loc) · 962 Bytes

Group Match

SQL Regex Logo

RegexGroupMatch() is a scalar function that lets you run a regular expression using named groups against a string. It returns the match for the group you've named. RegexGroupMatch() is a SQL CLR function that exposes the System.Text.RegularExpressions' Match() method.

Let's look at a few examples, inspired by a handy Regular Expressions tutorial

Screenshot

Group Match SSMS example

Retrieve the domain of an email address

declare @regex_pattern varchar(max) = '[_]*([a-z0-9]+(\.|_*)?)+@(?<domain>([a-z][a-z0-9-]+(\.|-*\.))+[a-z]{2,6})'

select dbo.RegexGroupMatch('My email address is [email protected]', @regex_pattern, 'domain')