Friday, July 06, 2007

SQL 2005 CLR/.Net Regular Expression Library

CodeProject - A T-SQL Regular Expression Library for SQL Server 2005

"With the advent of CLR integration into SQL Server 2005, it has become incredibly easy to extend the power of the T-SQL programming language. Two of the areas that can be improved upon by way of CLR integration are string matching and string manipulation.

...

My objective here is to wrap some of the more commonly used static methods of the RegEx class in the .NET Framework into something useable in a T-SQL environment. I felt the best approach was to develop this wrapper as a set of user defined functions that closely mirror the inputs and outputs of these methods in the RegEx class.

..."

Functions

ufn_RegExIsMatch The purpose of this function is to mirror the functionality of the Regex.IsMatch method. ...

ufn_RegExMatches While ufn_RegExIsMatch will tell you if there is a match of @Pattern within @Input, this function will tell you what the matches are, where they are located in the string and how long each match is.  ...

ufn_RegExReplace This function mirrors the functionality of Regex.Replace in the .NET Framework...

ufn_RegExSplit Splitting a delimited string into its elements is a common task among T-SQL developers. The ufn_RegExSplit function does exactly that. This implementation uses the Regex.Split method ...

..."

Nice. With SQL 2005, CLR RegEx wrapping is often talked about, but rarely put together in as good a package as this. Not only is the library talked about, but its deployment as well...

1 comment:

Demon said...

Regular expression is really wonderful to parsing HTML or matching pattern. I use this a lot when i code. Actually when I learn any new langauge, first of all I first try whether it supports regex or not. I feel ezee when I found that.

http://icfun.blogspot.com/2008/04/ruby-regular-expression-handling.html

Here is about ruby regex. This was posted by me when I first learn ruby regex. So it will be helpfull for New coders.