Code Review: CLR RegexSubstring
- by OMG Ponies
Could this be better? .NET 2.0 compatibility for SQL Server 2005:
public static SqlString RegexSubstring(SqlString regexpattern,
SqlString sourcetext,
SqlInt32 start_position)
{
SqlString result = null;
if (!regexpattern.IsNull && !sourcetext.IsNull && !start_position.IsNull)
{
int start_location = (int)start_position >= 0 ? (int)start_position : 0;
Regex RegexInstance = new Regex(regexpattern.ToString());
result = new SqlString(RegexInstance.Match(sourcetext.ToString(),
(int)start_position).Value);
}
return result;
}