Free Libraries

Online Help

SQL Server Regex

Introduction

Finding or replacing text in SQL is a very frequent scenario. “LIKE” and “PATHINDEX” are often used but, unfortunately, are not close to be as much powerful and offering the same possibilities as regular expression (Regex) does.

Eval SQL.NET lets you use and exploit fully C# regular expression features directly in T-SQL stored procedures, functions and triggers. It’s possible to use regex in SQL search condition and select statement.

Example

Discussion

If you are currently using an fn_split User-Defined Functions (UDF), this benchmark will probably make change your mind!

Methods

1,000 rows

10,000 rows

100,000 rows

1,000,000 rows

Eval SQL.NET

4 ms

13 ms

160 ms

1,650 ms

fn_split (TVF)

100 ms

625 ms

5,500 ms

55,000 ms

Conclusion

Eval SQL.NET offers all advanced C# regular expression features in T-SQL statements and search conditions. Even more, you can use C# syntax to return from SQL what you really want and not only the regex result.

While it should never replace scenarios where pure SQL operators/functions such as “LIKE” and “PATHINDEX” are sufficient, Eval SQL.NET will help you easily cover all unsupported ones.