From: Robert Klemme Date: 2013-02-23T01:09:05+09:00 Subject: Re: Questionable regex performance when using lazy matching and inverted character classes On Fri, Feb 22, 2013 at 4:24 PM, Tikhon B. wrote: > I took another look at the anchors ruby provides, and I found that the > \G anchor actually solves the issue outlined in this particular example > as it applies in my real use case to my satisfaction. Good! > I'm still a bit unsettled that there is such a caveat to consider when > writing a relatively benign expression. I actually believe this is just one more item to watch out for when creating regular expressions. Many expressions I see posted (here and elsewhere) are done a bit sloppy and will match properly with the few inputs the user is considering right now but break with other inputs. I believe you can say the art (?) of creating regular expressions is not well developed on average. > However, given what the symptoms > of the problem imply about the engine design, I suspect fixing the issue > would take quite a bit of either hackery, or a fair amount of re-design. Have you read "Mastering Regular Expressions"? If not, it's a good read about the matter. Backtracking occurs in every regexp engine which is implemented with a NFA and so every of those engines is in principle vulnerable here. It's different for DFA based engines which do not need backtracking. But today's regexp engines usually use a NFA (with sed being a prominent exception) because of the greater flexibility. It's a trade off and you always pay a price. :-) Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/