0

I am learning regular expressions and I came across this example as for how not to write them.

/([01]+)+b/

The reason mentioned is that it is very inefficient since it involves a lot of backtracking. Can someone explain why and what would be its efficient version?

Katana
  • 401
  • 3
  • 22
  • 2
    By all means use `[01]+b` – Wiktor Stribiżew Aug 22 '18 at 21:52
  • @WiktorStribiżew but what of you need a capture group? ;) – epascarello Aug 22 '18 at 21:56
  • Nested quantified overlapping terms, or singular unique terms are the only cause of catastrophic backtracking. Java, by contrast, has a stack problem separate issue that causes an overflow when you use an alternation group that is quantified. The people that posted answers in that duplicate link couldn't recognize a bad pattern 9 out of 10 times. All those answers failed. –  Aug 23 '18 at 00:25

0 Answers0