Jul 22, 2020 02:01 AM|yij sun|LINK
Accroding to your description,as far as I think,the regular expression checks for whole words only and it It invokes the compiler to build an entire new chunk of code, creates a new app domain and loads it in there, then calls it (across app domains).
The regex changes every search, there's no reuse to amortize the cost of compiling and loading the generated code. Absolutely remove the RegexOptions.Compiled flag.
If you need to improve the execution speed,you could do:
1.Keep your syntax simple as possible.
2.Precompile your regular expression pattern by using qr// if you're using that regular expression in a loop. That'll prevent Perl from having to compile your regular expression with each loop.
3.Try to avoid regular expression syntax that has to do backtracking. This usually ends up being the most general matching patterns (such as .*).
As to regular expressions in general, I recommend updating to .Net 5, there have been marked improvements of up to 95% for regex matching, especially simple ones like yours.