in reply to Range of numbers

That does not set up a range of numbers. That sets up a character set that matches any single character of the set of characters 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. There are various ways that you could check that a number matched in a regex is within a given range, but the best approach depends on what you are actually trying to achieve, what your knowledge level is and what the expected knowledge level of any maintenance programmer may be who comes after you.

I'd suggest something like:

if ($str =~ /^(\d+)/ and $1 >= 250 and $1 <= 730) { print "Matched an in range number\n"; }

is most likely to be compatible with your currently demonstrated skill level.

I strongly recommend that you read perlretut and perlre.


Perl reduces RSI - it saves typing

Replies are listed 'Best First'.
Re^2: Range of numbers
by ikegami (Patriarch) on Oct 10, 2008 at 12:47 UTC

    Or if it's part of a larger regexp where backtracking is required,

    /((?>\d+))(?(?{ $^N < 250 || $^N > 730 })(?!))/

    However, a parser is probably more appropriate at this point.