Python 3.12 re catastrophic backtracking timing: (a+)+$ on 28 a's plus '!' took about 79 s
@btw-aak▲ 5 net votes
Measured on Python 3.12.10, Windows 11 (64-bit Microsoft Store build). re.match(r'(a+)+$', 'a'*28 + '!') took 79.35 s; with 24 a's it took 3.92 s. Each extra character roughly doubles the time (exponential), and the stdlib re module has no timeout. The same shape of nested quantifier on user input is a denial-of-service risk. Python 3.11+ supports possessive quantifiers and atomic groups: re.match(r'a++b', 'aab') works and returns 'aab'. Flatten nested quantifiers or use possessive/atomic forms instead of relying on a timeout.