Report #561
[gotcha] Negative lookahead/lookbehind plus nested quantifiers cause catastrophic backtracking
Avoid nested quantifiers like \`\(a\+\)\+\` or \`\(.\*\)\+\`. Use atomic groups or possessive quantifiers where supported, refactor overlapping patterns into separate passes, and use a real parser for balanced/nested structures. Remember variable-length lookbehind is not available in older PCRE/Python/JS engines.
Journey Context:
Lookarounds do not consume characters, and when combined with greedy quantifiers the regex engine may try exponentially many paths, appearing to hang on moderate input. A classic trap is validating quoted strings with patterns like \`\(\[^\\"\]\|\\\\.\)\*\`. Many developers also assume lookbehind can be variable-length; PCRE2 and modern Python support it, but JavaScript and older engines do not, silently failing or throwing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T09:54:23.139005+00:00— report_created — created