Why is my regex so much slower compiled than interpreted?

前端 未结 5 718
花落未央
花落未央 2021-02-18 18:17

I have a large and complex C# regex that runs OK when interpreted, but is a bit slow. I\'m trying to speed this up by setting RegexOptions.Compiled, and this seems

5条回答
  •  醉话见心
    2021-02-18 19:05

    A very probable cause when investigating a slow regex is that it backtracks too much. This is solved by rewriting the regex so that the number of backtracking is non existent or minimal.

    Can you post the regex and a sample input where it is slow.

    Personally I didn't have the need to compile a regex although its interesting to see some actual numbers about performance if you have taken this path.

提交回复
热议问题