On 6/26/06, tom arnall <[EMAIL PROTECTED]> wrote:
> > 3 $_ = " [11] [22] a ";
> > 6 $re1 = qr/a|\[.*?\d\d\]/; > > 7 $re2 = qr/($re1\s)?$re1/; > > 8 ($f) = /($re2)/;
if line 6 is changed to '$re1 = qr/a|\[\d\d\]/', the result is '[11]'. how is '.*?' causing the different output?
When '.*?' is included, the first occurrence of $re1 matches '[11] [22]'. (Note the two spaces.) Next the single space before 'a' is matched; the second occurrence of $re1 matches the 'a'. Without '.*?', the optional clause matches the empty string; so the second occurrence of $re1 matches '[11]'. Remember, it matches at the first place in the string where it *can* match. Once the RE engine finds a match, it doesn't keep looking for another. Does that clear things up for you? Cheers! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>