Microsoft offers a method called Match that matches a Regex pattern starting at a specific position in the input string. What I am trying to do is opt开发者_C百科imize the performance of my program by using the static method version of Match, there by gaining the benefit of caching. There does not seem to be a way to specify a specific position to start matching though, even though the member version does. Is there anyway to emulate this or is there an alternate static method I'm missing that allows me to start searching for my pattern at a specific spot in the input string? Any help would be appreciated.
If you use a disassembler tool like DotPeek to look inside the System.dll, you'll see that the implementation of the static function creates a new Regex object:
public static Match Match(string input, string pattern)
{
return new Regex(pattern, RegexOptions.None, true).Match(input);
}
public static Match Match(string input, string pattern, RegexOptions options)
{
return new Regex(pattern, options, true).Match(input);
}
So in fact it's just the opposite - the static function has worse (or at least not better) performance.
精彩评论