The library’s catalogue kiosk: /^(a+)+$/ runs in a worker that stops it after 400 ms while the page keeps running. When does it freeze, and when does it…
Why it matters
ReDoS has taken down Cloudflare and Stack Overflow. Seeing the ways explode, and that it only happens when the match fails, lets you spot a dangerous pattern and fix it, rather than memorise rules.
The key idea
A nested quantifier explodes exponentially, but only when the match fails
Try it in this playground
Freeze the kiosk With ^(a+)+$, move the number of a's until the real engine is stopped. This page keeps running.
Play the ways With a few a's, step through the ways one at a time: every round is ringed on the board.
Remove the '!' at the end The same nested pattern, 20 a's or more, finishes at once: the first way matches.
Fix it with ^a+$ The same answer, but only as many ways as letters: linear.