inline. On Monday 26 June 2006 12:37 pm, Tom Phoenix wrote: > 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 >!!!!!!!!!!!!!!snip!!!!!!!!!!!
> > > > 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. > if line 6 is changed to '$re1 = qr/a|\[\d\d\]/', the result is '[11]'. how is '.*?' causing the different output? > > 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'. -- thanks, tom arnall north spit, ca -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>