A really general regexp that you might use looks like this:
my $txt = "169.254.0.210"; if($txt =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.(\d{1,3})/ and ($1 < 250 && $1 > 220)) { print "VALID ADDRESS!\n"; }
You might notice the pattern in the regexp that looks like \d{1,3}\. which means "match any number at least one time, and no more than three times and then a dot". This is a very general IP pattern. The above code also matches the last set (via the parenthases), and then compares it in the other half of the if statement.

To apply it to your specific example:
if($ip =~ /123\.45\.678\.(\d{1,3})/ and ($1 < 1 and $1 > 126)) #code here
If you are SURE of the first three octects of your IP address, this will work just fine for you. Hope this helps.

    --jb

Update In response to Amel's posting, yes, you'd have to test it for IP validity (and I wouldn't use it to match a whole IP in reality), but it matches the general pattern, and will work simply if all you need to test is the last octect. Zero is a valid IP digit if not in the first or last octect.

In reply to Re: Clueless newbie - help! by JayBonci
in thread Regular expression range question (was: Clueless newbie - help!) by odosbucket

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.