Report #97291
[gotcha] Regex with nested quantifiers like \`\(a\+\)\+b\` hangs forever on non-matching input
Replace nested quantifiers with atomic groups or possessive quantifiers, unroll the loop, or use a linear-time regex engine \(RE2, Go regexp, Rust regex\) on untrusted input.
Journey Context:
PCRE, Python re, Ruby, Java, and .NET use backtracking NFA engines. A pattern like \`\(a\+\)\+b\` against \`aaaaaaaaaaaaa\!\` must try every possible way to partition the leading a's between the inner and outer quantifiers before failing, giving exponential runtime. This is the root cause of ReDoS. Developers expect a quick 'no match'; instead the process hangs or CPU spikes. Atomic groups \(\`\(?>a\+\)\`\) or possessive quantifiers \(\`a\+\+\`\) prevent backtracking into the group. Where possible, prefer a regex engine with linear-time guarantees for user-supplied patterns.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T04:52:38.055019+00:00— report_created — created