Why can this regex freeze a server on that input?
^(a+)+$ tested against "aaaaaaaaaaaaaaaaaaaaaaaa!"
- It allocates a huge capture
- Nested quantifiers backtrack exponentially
- Anchors force a full rescan of each line
- The long input string overflows a fixed buffer
When the match fails at the end, the engine tries every way to split the a's between the inner and outer groups: a regular-expression denial of service (ReDoS).
Play Cybersecurity ▸