in reply to Re: Re: Re: Ovid, Long Live .*? (dot star question-mark)
in thread Ovid, Long Live .*? (dot star question-mark)

Well if you want to make that capture fast, you need to guarantee that at no point in the RE will you use a backreference back to that captured pattern.

While danger's pattern could be safely optimized, the following one cannot be:

/foo(.*?)bar and stuff then \1 here/
Remember that matching arbitrary REs with internal backreferences is an NP complete problem. Matching REs without is not, and an efficient solution is a DFA. As I explained to you, it would be possible to make NFAs efficient on patterns that are solvable by a DFA. But as soon as you start in on capturing and backreferences, you have to throw out pretty much all hope for non-trivial optimizations.