On 10/16/06, Richard Lynch <ceo@xxxxxxxxx> wrote:
On Mon, October 16, 2006 2:54 pm, Chrome wrote: > *edit* sorry I didn't think and just hit reply on this instead of > reply > all... sorry Richard */edit* > > [snip] > .*? is kinda silly -- .* mean "0 or more characters", and ? means > "maybe" > but putting them together has no added value, so lose the ? > [/snip] > > I could be wrong (and under the considerable knowledge of Richard I > certainly feel it :) ) but doesn't the ? after a quantifier signify > that > preceding pattern is to be taken as ungreedy? You're right; I'm wrong. I'm not PCRE expert. Took me 20 years to be able to stumble through the simplest expressions. ? means "maybe" in some other place in PCRE. Or maybe that's POSIX. Never have figured that one out.
The ? after * means ungreedy only.. so your basic: a? means a or no a in the regular usage The easiest to remember is that ? two basic definitions: - extend the meaning of - 0 or 1 of the previous expression /foo(?i)bar/ matches FOoBar, fOObar, foobar.. the (?i) extends the meaning of (?[modifer-list]) to contain modifiers of the previous expression and no more /foo.*?bar/ is the same thing as saying /foo.*(?U)bar; a short cut, much like what \d is a shortcut to [0-9] /foo(?<....)/ a look behind assertion /foo(?=...)/ a look ahead assertion (and a negative of the assertions are allowed) /foo(?(condition)yes:no)/ condition usually being an assoertion of some sort I still dont understand it, and it is one of the reasons why people have problems using regex, it really is a whole different language, using Regex Coach as chrome did, is the probably the best way to find out the problem or how to match what you are looking for... A nice little overview (although i have read it about a few dozen times and still cant apply the logic 100% of the time) php.net/reference.pcre.pattern.syntax.php on the other hand, people still want html parsers written in PCRE.. :) Curt. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php