in reply to Re: Validate Ip address Regexp
in thread Validate Ip address Regexp

Thanks a ton!! helped me to understand a lot and significance of ^ and $

Replies are listed 'Best First'.
Re^3: Validate Ip address Regexp
by AnomalousMonk (Archbishop) on Nov 28, 2015 at 13:52 UTC

    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:  <%-{-{-{-<