views:

4985

answers:

3

Is there any regular expression library written in T-SQL (no CLR, no extended sp, pure t-sql) for SQL Server?

(should work with shared hosting)

Edit:

  • thanks I know about PATINDEX, LIKE, xp_ sps and CLR solutions

  • I also know it is not the best place for regex, the question is theoretical:)

  • reduced functionality is also accepted

A: 

You could try this project though I haven't used it. It might not be a good idea to do it in the database though as that is not what databases are designed for.

Richard Nienaber
A: 

There is some basic pattern matching available through using LIKE, where % matches any number and combination of characters, ? matches any one character, and [abc] could match a, b, or c... There is more info on the MSDN site.

Steven Murawski
+1  A: 

How about the PATINDEX function?

The pattern matching in TSQL is not a complete regex library, but it gives you the basics.

(From Books Online)

Wildcard  Meaning  
% Any string of zero or more characters.

_ Any single character.

[ ] Any single character within the specified range 
    (for example, [a-f]) or set (for example, [abcdef]).

[^] Any single character not within the specified range 
    (for example, [^a - f]) or set (for example, [^abcdef]).
Eric Z Beard