in reply to Re: Regex host portion of IPv6 address
in thread Regex host portion of IPv6 address

Thanks for the response. Your code goes beyond my understanding. I thought I was close with my code. ;-)
if ($line =~ m{\s+Prefix\s+((.*)::(\w{1,4})/(\d{1,3}))} ) { $ipv6Address = "$1::$2/$3"; }
I am able to match

Prefix 2001::1/128
Prefix 2001::2/128

but not

Prefix 2001:1::/64

Replies are listed 'Best First'.
Re^3: Regex host portion of IPv6 address
by quester (Vicar) on Mar 28, 2008 at 22:28 UTC

    The part that's hard to see is that there must be exactly one double colon :: in the address ... unless there are exactly seven colons, in which case there must be no double colon. For example,

    0001:0002:0003:0004:0005:0006:0007:0008
    

    The other and more important thing - which I forgot altogether - is that addresses that are mapped from IPv4 to IPv6 can optionally be written with the last two groups of hex digits replaced by a dotted-decimal IPv4 address, as in these two:

    ::ffff:10.32.12.1
    ::10.32.12.1
    

    which are equivalent to

    ::ffff:0a20:0c01
    ::0a20:0c01
    

    I think the suggestion from an Anonymous Monk of "Work less, use Net::IPv6Addr" is really a much better idea.

    Adding the code to parse mapped address would turn the code I suggested from a mess into an abomination... a useful one to be sure, but still very very abominable. As Otto von Bismark might say, "Some CPAN modules are like laws and sausages, it is better not to see them being made."