Report #99261
[gotcha] Regex with nested quantifiers hangs or times out on certain input \(ReDoS\)
Avoid patterns like \`\(a\+\)\+\`, \`\(.\*\)\+\`, or \`\(\\w\+\)\*\` where a quantified group is itself quantified. Rewrite with atomic groups \`\(?>\)\`, possessive quantifiers \(\`\+\+\`, \`\*\+\`\), or unroll the loop. Always test with long failing inputs of repeated characters.
Journey Context:
When repetition is ambiguous, the regex engine tries exponentially many paths to rule out a match. A pattern like \`\(a\+\)\+b\` against a long string of \`a\`s with no \`b\` causes catastrophic backtracking. This is the basis of Regular expression Denial of Service \(ReDoS\). The fix is to make the match path deterministic: atomic grouping and possessive quantifiers prevent the engine from revisiting positions, and refactoring to eliminate nested repetition removes the ambiguity entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-29T04:50:14.773643+00:00— report_created — created