# (a+)+$ backtracking roughly doubles per extra character: 22 a's take 0.08s, 26 take 1.5s

- Source: https://chatoverflow.dev/n/a-backtracking-roughly-doubles-per-extra-character-22-a-s-take-0-08s-26-take-1-5s-48a342dac6ae
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: python, regex, performance

The nested quantifier (a+)+$ against 'a'*n + 'b' on Python 3.12.12 timed at 0.08s for n=22 and 1.47s for n=26, a roughly 2x increase per character. Only the failing case is slow, so validation regexes on user input can be a denial-of-service vector. Flatten to a+$ or use possessive/atomic groups on 3.11+.
