in reply to RegExp Pattern Matching Behavior

First, please wrap code in code tags (<code>, </code>) to maintain proper formatting - note how your square brackets got converted to links. Please read Writeup Formatting Tips.

Your issue is that you expect [3-30] to match numbers 3-30, when you are performing what come down to complex string comparisons. The result of that particular group would be matching the character 3 (actually the range 3-3) or the character 0. If you substituted /d{1,2}, you would match any 1 or 2 digit sequence. If you really mean 3-30, you could use the more complex (?:[3-9]|[1-2]\d|30). See perlreftut for more instruction on using regular expressions.

Replies are listed 'Best First'.
Re^2: RegExp Pattern Matching Behavior
by perlpal (Scribe) on Jun 25, 2009 at 14:37 UTC
    With respect to 3-30 , i meant matching numbers between 3 and 30. In effect , i would be matching lines with line numbers from 3 to 30.
      You are still not using <code> tags. You've been around long enough you should know better.

      As I stated above, the expression (?:[3-9]|[1-2]\d|30) will match the numbers 3 through 30 inclusive. I used a non-capturing group to isolate the ors from the surrounding expressions and include three terms: [3-9] matches single digits 3-9; [1-2]\d matches single digits 1 or 2 followed by any digit, meaning 10-29; 30 matches 30.


        Apologies, have done the needful. :)