On 6/26/06, tom arnall <[EMAIL PROTECTED]> wrote:
1 #!/usr/bin/perl -w 2 3 $_ = " [11] [22] a "; 4 5 #with .*? 6 $re1 = qr/a|\[.*?\d\d\]/; 7 $re2 = qr/($re1\s)?$re1/; 8 ($f) = /($re2)/; 9 print "with .*? : $f\n"; 10 11 #without .*? 12 $re1 = qr/a|\[\d\d\]/; 13 $re2 = qr/($re1\s)?$re1/; 14 ($f) = /($re2)/; 15 print "without .*? : $f\n"; gets this result: with .*? : [11] [22] a without .*? : [11]
But shouldn't the '?' in '.*?' cause the search to terminate at the first ']' and yield the same result as the expression in Line 12?
No, because there are two spaces between the square brackets, so the pattern fails to match until it gobbles up the second closing bracket.
also, why should removal of the 'a|' in $re1 make any difference in the behavior of the expression? in fact, the removal causes the regex to return '[11]', i.e., allows the '?' quantifier to work.
It should make a difference because the second occurrence of $re1 can match 'a'. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>