http://www.perlmonks.org?node_id=1218215


in reply to Regex to catch IPV4 and IPV6 whenever ip appears withing brackets

Perl probably has a module for that: Regexp::IPv4 Regexp::IPv6

  • Comment on Re: Regex to catch IPV4 and IPV6 whenever ip appears withing brackets

Replies are listed 'Best First'.
Re^2: Regex to catch IPV4 and IPV6 whenever ip appears withing brackets
by Theodore (Friar) on Jul 10, 2018 at 08:31 UTC
Re^2: Regex to catch IPV4 and IPV6 whenever ip appears withing brackets
by theravadamonk (Scribe) on Jul 10, 2018 at 07:26 UTC

    Hmm, Many thanks for your INPUT. Really profitable for me,

    Here I TEST it with below code

    #!/usr/bin/perl use strict; use warnings; use Regexp::IPv4 qw($IPv4_re); use Regexp::IPv6 qw($IPv6_re); my $ipv4_address = "192.168.0.10"; my $ipv6_address = "2600:3c00::f03c:91ff:fedf:f016"; $ipv4_address =~ /^$IPv4_re$/ and print "IPv4 address\n"; $ipv6_address =~ /^$IPv6_re$/ and print "IPv6 address\n";

    Hmm. It Works