broomnew has asked for the wisdom of the Perl Monks concerning the following question:

I'm not silly enough to think I've found a bug, I must be doing something I simply don't understand.

Using perl 5.8.4.

I typod and missing the closing curly brace in a numeric range in a regular expression. It did not error out, only missed the matches I expected in my test.

Would this be considered correct behaviour?

Sample code:
#!/usr/bin/perl -w use strict; while (<DATA>){ chomp; # # Incorrect REGEXP - missing closing curly ! # V if (/(&[A-Z0-9\.]+:LU)((\d{1,2};\d{1,2})|(\d{1,2)|LD|LC)?/){ my $lookup = $1; my $type = $2; $type ||= ''; print "1. Lookup: [$lookup]:[$type]:[$_]\n"; } # # Correct REGEXP - notmissing closing curly ! # V if (/(&[A-Z0-9\.]+:LU)((\d{1,2};\d{1,2})|(\d{1,2})|LD|LC)?/){ my $lookup = $1; my $type = $2; $type ||= ''; print "2. Lookup: [$lookup]:[$type]:[$_]\n"; } } __DATA__ &&STOP &&JUMP(&VAR2:LU,NE,SPACES)026 &&JUMP(&VAR2:LU2,NE,SPACES)026 &&JUMP(&VAR2:LU23,NE,SPACES)026 &&JUMP(&VAR2:LU23;24,NE,SPACES)026 &&JUMP(&VAR2:LULD;24,NE,SPACES)026 &&JUMP(&VAR2:LULC;24,NE,SPACES)026 &&JUMP027

Replies are listed 'Best First'.
Re: Odd closing brace issue
by derby (Abbot) on Apr 08, 2005 at 18:31 UTC
    Not really. From the perlre:

    The following standard quantifiers are recognized:
    
       *      Match 0 or more times
       +      Match 1 or more times
       ?      Match 1 or 0 times
       {n}    Match exactly n times
       {n,}   Match at least n times
       {n,m}  Match at least n but not more than m times
    
    (If a curly bracket occurs in any other context, it is treated as a regular character.  In particular, the lower bound is not optional.) 
    

    So in the *Incorrect* regex is valid - match any digit followed by, literally, {1,2 (&&JUMP4{1,2SCOOBY would match).

    -derby
Re: Odd closing brace issue
by tlm (Prior) on Apr 08, 2005 at 18:33 UTC

    Add this line to your data, and you'll see what's happening:

    &&JUMP(&VAR2:LU2{1,2foobarbaz

    the lowliest monk