Report #2115
[gotcha] Regex with nested quantifiers hangs or crashes on long input
Avoid patterns like \(a\+\)\+, \(.\*\)\+, or nested groups with overlapping alternatives. Prefer possessive quantifiers \(\*\+, \+\+\) or atomic groups \(\(?>...\)\) where supported, or rewrite using negated character classes \(e.g., \[^"\]\* instead of .\*? in quoted strings\). Always test with adversarial input.
Journey Context:
Backtracking regex engines try every way to split repeated groups. \(a\+\)\+ against a long string of a's followed by a non-matching character creates exponential paths. This is the \#1 cause of ReDoS. Many 'email' and 'quoted string' regexes collapse because of an inner .\+ plus outer repetition. Non-greedy quantifiers do not fix the problem — the engine still backtracks. Possessive/atomic groups prevent backtracking; a parser or finite automaton eliminates it entirely. If your engine lacks atomic groups \(older Python\), restructure the pattern so repeated parts cannot match the same text in multiple ways.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T09:58:35.177511+00:00— report_created — created