Run regular expressions in SQL Server
C# PLSQL PLpgSQL
Switch branches/tags
Nothing to show
Clone or download

README.md

SQL Server Regex

SQL Regex Logo

SQL-Server-Regex gives you the power to run regular expressions inside SQL Server queries. It works by using SQL CLR functions to call the C# System.Text.RegularExpressions library.

Examples

Match

The RegexMatch() scalar function lets you call a regular expression against a string, and returns the first result if there is a match.

Match SSMS example

Matches

The RegexMatches() table-valued function lets you call a regular expression against a string, and returns all matches.

Matches SSMS example

Group Match

The RegexGroupMatch() scalar function lets you call a regular expression with named groups against a string, and returns the group name you specify.

Group Match SSMS example

Replace

The RegexReplace() scalar function lets you call a regular expression to find-and-replace inside a string. You can also match parts of a string and re-arrange them using references.

Replace SSMS example

Split

The RegexSplit() table-valued function lets pass a regular expression against a string to split it into pieces, and returns the pieces.

Split SSMS example

Installation

You can install sql-server-regex on most versions of SQL Server. This works the same for virtual machines or cloud VMs.

You can also install sql-server-regex onto AWS RDS.

Note: for SQL Server 2005, 2008, and 2008R2, if you can't install the DLL directly, you may you need to compile the assembly yourself using .NET 2.0 and an old version of Visual Studio.

Testing

This work has been tested, both for functionality and performance.

Resources