On 8/2/07, Tony Heal <[EMAIL PROTECTED]> wrote:
> So since '?' will match the last character, group, or class 0 or 1 time the 
> it matches the group of whatever happens to
> be in '.*' up to any spaces that are attached to the '$'.
>
> Is that correct?
snip

No, the ? in .*? is not the same as the ? in [abc]?  just like neither
of them are the same as the ? in (?foo)  The character is being
reused, but the meanings are completely separate.  The ? character
when used with a quantifier (i.e. *, +, ?, {n}, or {n,m}) means "match
the smallest possible string" (non-greedy).  The default for those
modifiers is to match the largest string possible (greedy).

from perldoc perlre:
       The following standard quantifiers are recognized:

           *      Match 0 or more times
           +      Match 1 or more times
           ?      Match 1 or 0 times
           {n}    Match exactly n times
           {n,}   Match at least n times
           {n,m}  Match at least n but not more than m times
snip
       By default, a quantified subpattern is "greedy", that is, it will match
       as many times as possible (given a particular 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 "?".  Note that the meanings don't change, just the "greediness":

           *?     Match 0 or more times
           +?     Match 1 or more times
           ??     Match 0 or 1 time
           {n}?   Match exactly n times
           {n,}?  Match at least n times
           {n,m}? Match at least n but not more than m times

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to