Skip to content

Latest commit

 

History

History
24 lines (13 loc) · 911 Bytes

matches.md

File metadata and controls

24 lines (13 loc) · 911 Bytes

Matches

SQL Regex Logo

RegexMatches() is a table-valued function that lets you run a regular expression against a string. All of the matched 'chunks' inside the string are returned. RegexMatches() is a SQL CLR function that exposes the System.Text.RegularExpressions' Match() method.

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

Screenshot

Regex Matches

Grabbing HTML Tags

Let's grab HTML tags out of text.

declare @regex_pattern varchar(max) = '<([A-Z][A-Z0-9]*)\b[^>]*>(.*?)</\1>'

select *
from dbo.RegexMatches('The HTML is <TAG>one</TAG><TAG>two</TAG>', @regex_pattern)