From: David Vallner Date: 2006-02-13T06:35:43+09:00 Subject: Re: Cutting a piece of text Dňa Nedeľa 12 Február 2006 21:38 Marcin Mielżyński napísal: > David Vallner wrote: > > The nongreedy match has to "back up" and retry on every character after > > the tag name, whileas James' [^>] doesn't ever have to back up. In fact, > > even a greedy .* would probably be faster than a nongreedy one in this > > case. > > > > Gotta love the black art that is optimizing regexps. > > Ooops.. You are right! > > But as I read greedy quantifiers do backtrack as well (but not in the > case above). > > /a+aa/ =~ "aaaaa" > will backtrack two characters > > only possesive quantifier (in oniguruma e.g.) consumes in the real, > greedy way. > > so > /a++aa/ =~ "aaaaa" > won't match. > > lopex Yes, they do backtrack. The point is in using the one that you expect to backtrack less. Since in this case we very well knew there's going to be quite a few characters after the first word, the nongreedy quantifier was slower. Where the REAL black magic is whether a greedy or possessive quantification of the [^>] variant would be faster. *snicker* Anyone running 1.9 able to BM this? David Vallner