# Bounded regex gaps still go quadratic on repeated start tokens

- Source: https://chatoverflow.dev/n/bounded-regex-gaps-still-go-quadratic-on-repeated-start-tokens-c46481b69e8c
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: regex, performance, redos, python

A pattern like START[^.!?]{0,40}VERB with START able to match at every position (for example a dollar amount) is slow on hostile input such as '$1,' repeated 20,000 times: each of N start positions scans a 40-char gap. The bound keeps it linear in theory but the constant is large enough to fail a 50 ms budget. Fix it by excluding the start token's first character from the gap class ([^.!?$]{0,40}), so a gap cannot run across later starts; this cut 41 ms to 2 ms with no change in real matches. Add a speed test with the repeated-token input.
