Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
20 lines (11 sloc) 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 fakeemail@hotmail.com', @regex_pattern, 'domain')