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

I agree with the CPAN recommendation. The reason I was taking my approach was to extract the IPv6 address from strings of text, then break it down. Net::IPv6Addr::ipv6_parse works great for the latter, but I am still trying to figure out the first part.
  • Comment on Re^2: Regex host portion of IPv6 address

Replies are listed 'Best First'.
Re^3: Regex host portion of IPv6 address
by Anonymous Monk on Mar 29, 2008 at 08:30 UTC
    UTSL
    my %ipv6_patterns = ( 'preferred' => [ qr/^(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}$/i, \&ipv6_parse_preferred, ], 'compressed' => [ ## No, this isn't pretty. qr/^[a-f0-9]{0,4}::$/i, qr/^:(?::[a-f0-9]{1,4}){1,6}$/i, qr/^(?:[a-f0-9]{1,4}:){1,6}:$/i, qr/^(?:[a-f0-9]{1,4}:)(?::[a-f0-9]{1,4}){1,6}$/i, qr/^(?:[a-f0-9]{1,4}:){2}(?::[a-f0-9]{1,4}){1,5}$/i, qr/^(?:[a-f0-9]{1,4}:){3}(?::[a-f0-9]{1,4}){1,4}$/i, qr/^(?:[a-f0-9]{1,4}:){4}(?::[a-f0-9]{1,4}){1,3}$/i, qr/^(?:[a-f0-9]{1,4}:){5}(?::[a-f0-9]{1,4}){1,2}$/i, qr/^(?:[a-f0-9]{1,4}:){6}(?::[a-f0-9]{1,4})$/i, \&ipv6_parse_compressed, ], 'ipv4' => [ qr/^(?:0:){5}ffff:(?:\d{1,3}\.){3}\d{1,3}$/i, qr/^(?:0:){6}(?:\d{1,3}\.){3}\d{1,3}$/, \&ipv6_parse_ipv4, ], 'ipv4 compressed' => [ qr/^::(?:ffff:)?(?:\d{1,3}\.){3}\d{1,3}$/i, \&ipv6_parse_ipv4_compressed, ], );