I use a permanent set of about eleven regular expressions to parse about 80k – 200k characters long strings. So far I just used new Regex(@"blah") in every place where I had to use Match(String, Int32), Replace(String, String) and Replace(String, MatchEvaluator).
But using these instance methods does not take advantage of the .NET’s regular expressions cache. So I want to refactor my code to use static methods instead. The problem is I can’t find a static equivalent of Match(String, Int32).
I thought about just using String.Substring(Int32) as appropriate but as far as I know it would allocate new String for me.
Do I have some other options?
You can create a static instance of the 11 regexes and use it everywhere.
Or you can create a static singleton object which contains the regexes.