Report #707
[gotcha] Regex with nested quantifiers and alternation hangs or runs exponentially
Avoid patterns like \(a\+\)\+, \(.\*\)\*, or nested alternation inside lookaheads/lookbehinds against untrusted input. Use possessive quantifiers \(\+\+ or \*\+\) or atomic groups \(\(?>...\)\) if your engine supports them; otherwise rewrite to eliminate nested repetition. Prefer linear-time engines such as RE2, Go regexp, or Rust regex for untrusted data.
Journey Context:
A pattern like ^\(?\!.\*foo\).\*bar can explode on strings without foo because the negative lookahead's .\* backtracks over every position. This is ReDoS: regular expression denial of service. Linear-time engines reject or rewrite these patterns by avoiding backtracking. PCRE, Perl, Python, and JavaScript backtrack by default. The fix is either to use a guaranteed-linear-time engine or to refactor so no quantifier contains another quantifier over overlapping character classes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T11:55:39.255672+00:00— report_created — created