I have a very simple CLR function to do regex matching
public static SqlBoolean RegExMatch(SqlString input, SqlString pattern)
{
if (input.IsNull || pattern.IsNull)
return SqlBoolean.False;
return Regex.IsMatch(input.Value, pattern.Value, RegexOptions.IgnoreCase);
}
This allows me to write a SQL Like statement.
SELECT * FROM dbo.table1 WHERE dbo.RegexMatch(column1, '[0-9][A-Z]') = 1
-- match entries in col1 like 1A, 2B etc...
I just think it would be nice to reformulate this query so that it can be called as
SELECT * FROM dbo.table1 WHERE column1 REGEXLIKE '[0-9][A-Z]'
Is it possible to create new comparison operators using the CLR code. (I guess from my brief look at the website that the answer is NO , but without harm)
source
share