You don&#x27;t need to throw out your favorite regex features—backreferences aren&#x27;t stupid, they&#x27;re useful and usually harmless! Rather, a good regex engine should start with recursive backtracking (ideally JIT&#x27;d) and fall back to the Thompson NFA if the regex supports it and the recursive backtracking approach is taking too long. Think of it like the adaptive sorting algorithms that switch between insertion sort and quicksort based on the size of the collection.<p>This approach gives you the best of both worlds: speedy operation in the common cases in which recursive backtracking beats the Thompson NFA, all the regex features you know and love, <i>and</i> worst case polynomial running time for regexes that the Thompson NFA supports.<p>I don&#x27;t think it would have prevented this bug, though, because I don&#x27;t think the Thompson NFA supports the recursive backreference thing that this regex uses.