I have the below regex here which is written to support the PRCE/PRCE2 format. However, this throws the following error “Evaluation takes too long. Please check your regular expression.” Is there any way we can improve the performance of this regex by simplifying it?
Also, the regex throws "catastrophic backtracking" error as well.
(\border\D*\W*)\d+(*SKIP)(*F)|(\border\D*number\W*)\d+(*SKIP)(*F)|(?<!x)(?=(?:[._ –-]*\d){9})(?!9|66\D*6|00\D*0|(?:\d\D*){3}0\D*0|(?:\d\D*){5}0(?:\D*0){3})\d(?:[._ –-]*\d){4}
The above regex has set of rules in it. Please find the requirements of the regex.
Regex101 is giving me the exact output as expected but it has a performance issue. Need to simplify it.
You may try this refactored regex:
\b(?>x|order(?>[\W_]*number)?[\W_]*)\d+(*SKIP)(*F)|(?=(?>[._ –-]*\d){9})(?>(?>9|6{3}|0{3}|(?>\d\D*){3}00|(?>\d\D*){5}0{4})(*SKIP)(*F)|\d(?>\D*\d){4})
Compared to your existing demo link it is taking almost half number of steps in the demo link.