SQL Server RegExp  

Posted in ,


sp_dbcmptlevel db_name, 90
EXEC sp_configure 'show advanced options' , '1';
go
reconfigure;
go
EXEC sp_configure 'clr enabled' , '1'
go
reconfigure;
EXEC sp_configure 'show advanced options' , '1';
go



public static partial class UserDefinedFunctions
{
public static readonly RegexOptions Options =
RegexOptions.IgnorePatternWhitespace |
RegexOptions.Singleline;

[SqlFunction]
public static SqlString RegexMatch(SqlChars input, SqlString pattern)
{
Regex regex = new Regex(pattern.Value, Options);
string data = new string(input.Value);
data.ToLower();
Match aMatch = regex.Match(data);
return aMatch.ToString();
}
};



select dbo.RegexMatch( N'123-45-6789', N'\d{2}' )

http://msdn.microsoft.com/en-us/magazine/cc163473.aspx

metanews


Add to Google