David T-G wrote:
> % you can make the .* less greedy...
> %
> %   $text = preg_replace('/<!--.*?-->/', '', $text);
>
> How does that make it ungreedy?  The only thing I see relating
> question marks and greediness is that a question mark makes part of a
> regexp with a /U modifier (otherwise not greedy) back into a greedy
> portion.
>
> Am I missing something painfully obvious?

www.perldoc.com appears to be unavailable at the moment, but if you have "perldoc"
installed, here's an excerpt from the "perlre" man page:

       By default, a quantified subpattern is "greedy", that is,
       it will match as many times as possible (given a particu-
       lar starting location) while still allowing the rest of
       the pattern to match.  If you want it to match the minimum
       number of times possible, follow the quantifier with a
       "?".

There are other useful examples in that man page.  The "U" modifier is something
that PHP added, it is not part of perl's regex syntax.  It basically reverses the
greedy tendency, so that ALL of the quantifiers in a particular regex are ungreedy,
and the "?" makes them greedy.  Without the "U", the normal (and perl compatible)
behavior of "?" following a quantifier is to make it ungreedy.

HTH

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to