perl-diddler has asked for the wisdom of the Perl Monks concerning the following question:

I am having a problem seeing my problem (what else is new)? No, here, in this code:
> perl -we' use strict; use warnings; use P; my $tgt_RE1 = qr{ ([SK]) ([0-9]{1-3}) ([-_\.\w]+) }x; my $tgt_RE2 = qr{ ([SK]) ([0-9]{2}) ([-_\.\w]+) }x; my $pat="S01boot.usr-mount"; my @tstAr1 = $pat =~ /$tgt_RE1/; my @tstAr2 = $pat =~ /$tgt_RE2/; P "tstar1=%s", \@tstAr1; P "tstar2=%s", \@tstAr2;' tstar1=[] tstar2=['S', 01, "boot.usr-mount"]
Why isn't the match count in the 2nd paren working when I have a range of {1-3} (as in tgt_RE1), but does when I have a range of 2 (as in tgt_RE2)?

Sure looks like it *should* work, but how can it not match? FWIW, I had "\d" in place of 0-9 on an earlier revision of this test case.

*Scratching head*... thanks...

Replies are listed 'Best First'.
Re: "Str8-forward" RE prob? {w/range}
by Anonymous Monk on Oct 15, 2016 at 00:56 UTC
    my $tgt_RE1 = qr{ ([SK]) ([0-9]{1-3}) ([-_\.\w]+) }x;

    should be

    my $tgt_RE1 = qr{ ([SK]) ([0-9]{1,3}) ([-.\w]+) }x;

    The range isn't {1-3}, but {1,3}

    Note that underscore, _, is a word and dot doesn't need to be escaped in a character class.

      Oh, poo! RE: '_' -- I added it to my match string when the {x-y} didn't work (when it should have been ',')... tnx!
Re: "Str8-forward" RE prob? {w/range}
by Anonymous Monk on Oct 15, 2016 at 00:47 UTC

    a range of {1-3}

    Thats not a range, ie not a quantifier, thats a string, an exact match

Re: "Str8-forward" RE prob? {w/range}
by Anonymous Monk on Oct 15, 2016 at 00:45 UTC
    What does use re 'debug'; tell you?