in reply to Can you spot the problem?

This is my regex for Ip addresses:
(([01]?\d\d?|2[0-4]\d|25[0-5])\.){3}([01]?\d\d?|2[0-4]\d|25[0-5])

Replies are listed 'Best First'.
Re: Re: Can you spot the problem?
by hardburn (Abbot) on Mar 05, 2004 at 15:45 UTC

    Don't parse IP addresses with regexen in real code. The OP makes an amusing puzzle (one which I have admittedly not figured out yet), but nothing more. There are far more valid formats for IPv4 than the traditional dotted-quad one. I don't even want to think about all the formats available for IPv6.

    Look at Valid IP? for more info.

    ----
    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

      You can match an IP-address with a regexp, just don't try to roll your own, do  {use Regexp::Common; /$RE{net}{IPv4}/} instead.

        From the Regexp::Common::net docs:

        $RE{net}{IPv4}

        Returns a pattern that matches a valid IP address in "dotted decimal"

        So it only matches the traditional dotted-quad form of IPv4 addresses. That's just one format IPv4 can come in (albeit the most common). There are modifiers Regexp::Common allows for some other formats (like "dotted hex"), but not all possible formats (a simple 32-bit number, for example).

        ----
        : () { :|:& };:

        Note: All code is untested, unless otherwise stated