Now, and without using or looking at Regexp::Common::net or other such modules or Super Search, write, as an exercise (for it may be better in practice to use multiple regexes and separate tests), a single regex that will accept '255.1.12.123' and reject '256.1.12.123' or '300.1.12.123'. (Think of the alternate ranges (hint) of numbers involved: 0-9, 00-99, 000-199, 200-249, 250-255.) Then write a regex that will extract (or parse) valid IPv4 decimal octet addresses from an arbitrary string:
    'foo255.1.12.123bar1.2.3.4 x 11.2.33.44 y 300.123.12.1z000123.3.2.11111'
Now you've got something.

See perlre, perlretut, and perlrequick.


Give a man a fish:  <%-{-{-{-<


In reply to Re^3: Validate Ip address Regexp by AnomalousMonk
in thread Validate Ip address Regexp by akr8986

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.