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
> >     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.

but it gobbles to the 2nd ']' even if there is only one space between the ']' 
and '['.

Tom Arnall



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


Reply via email to