Regex Optimization
The code looks silly, precompiling the Regex each time it is called and
discarding the local variable. This block seems to cause some delay. Is
there any better way to do this?
public static bool IsExactMatch(string input, string pattern)
{
if (IsEmpty(input)) return false;
System.Text.RegularExpressions.Match m =
System.Text.RegularExpressions.Regex.Match(input, pattern,
RegexOptions.IgnoreCase | RegexOptions.Compiled);
if (!m.Success) return false;
return m.Groups[0].Value == input;
}
No comments:
Post a Comment