On 11/24/09 Tue  Nov 24, 2009  4:42 PM, "Orchid Fairy   (兰花仙子)"
<practicalp...@gmail.com> scribbled:

> On Wed, Nov 25, 2009 at 8:38 AM, Shawn H Corey <shawnhco...@gmail.com> wrote:
> 
>> 
>> It seems to be picking up an extra empty string after a non-zero length
>> match.
>> 
> 
> Thanks John and Shawn.
> Yup what let me be confused is that, why there is an additional empty
> string there?

You get 4 matches because there are four places in the string 'aXXXb' that
can be matched by 'X*'. Note that a "place" in this case is a position
between characters. The places are:

1. before the a
2. after the a
3. before the b
4. after the b

You could actually say that there are two additional places in the string
that can be matched by 'X*': after the first and second X's. However,
because the '*' modifier is "greedy", once it matches the first X, it
gobbles up the rest of the X's, so the next match attempt is started after
the last X. As a result, you get 4 matches total for the 'g' modifier, which
always starts a match test at the position following the previous match.



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to