I've noticed some code that uses the static method:
Regex.IsMatch([someRegexStr], [someInputStr])
Is it worth replacing it with the instance method? Like:
private readonly Regex myRegex = new Regex([someRegexStr]);
...
myRegex.IsMatch([someInputStr]);
One of the regular expression optimization recommendations in the following link: Regular Expression Optimization by Jim Mischel
For better performance on commonly used regular expressions, construct a Regex object and call its instance methods.
The article contains interesting topics such as caching regular expressions and compiling regular expressions along with optimization recommendations.
The last 15 regular expression internal representations created from the static call are cached.
I talk about this and the internal workings in "How .NET Regular Expressions Really Work."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With