this code:

     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]

The difference between the two sections of code is in Lines 6/12, i.e., the 
presence/absence of '.*?'. The regex in Line 6 seems to be using the 
second ']' in the target string to satisfy its '\]'. But shouldn't the '?' 
in '.*?' cause the search to terminate at the first ']' and yield the same 
result as the expression in Line 12? 

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.

Thanks,

Tom Arnall




-- 
thanks,

tom arnall
north spit, ca

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


Reply via email to