In production code, it might be worth expanding grinder's regexp to
use warnings; use strict; my @test_values = qw/ 26 231 232 233 234 254 255 256 025 0000 /; my $rx = qr /^ (?: 2 # first digit is a 2 (?: [6-9] # second and _last_ digit is + 6-9 | 5 # or second digit 5 [0-5]? # maybe third and _last_ dig +it 0-5 | [0-4] # or second digit 0-4 \d? # maybe followed by a final +third 0-9 )? | [3-9] # first digit 3-9 \d? # maybe followed by final 0- +9 | 1 # first digit 1 (?: \d\d? # maybe followed by 1 or 2 digi +ts )? | 0 # single-digit 0 ) $/x; foreach my $number ( @test_values ) { print "$number:", ($number =~ /$rx/ ? 'true' : 'false'), "\n", ; }
Which makes it easier to see that leading zeroes, as in 0000 or 025, wouldn't fit. That might be or not a problem, of course.

Krambambuli
---
enjoying Mark Jason Dominus' Higher-Order Perl

In reply to Re^2: does code help regex match numeric ranges? by Krambambuli
in thread does code help regex match numeric ranges? by AlwaysLearning

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.