Report #2985
[gotcha] Regex with nested quantifiers hangs or CPU-spikes on non-matching input
Avoid overlapping nested quantifiers such as \(a\+\)\+ or \(.\*?,?\)\+. Use atomic groups, possessive quantifiers, or unambiguous alternations. Test every regex against a long non-matching string and audit with a ReDoS checker.
Journey Context:
Most regex engines use backtracking NFA. Patterns with nested repetition create exponentially many paths to explore before giving up, causing ReDoS. This is especially common in validators for email, URLs, JSON, or deeply nested structures. The fix is structural: make the pattern linear by removing ambiguity, failing fast, or using a real parser. Security scanners flag these patterns for a reason; performance tests alone will not catch the worst cases.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T14:52:02.665340+00:00— report_created — created