in reply to IPAddress check

Hello vasanth.easyrider,

This question has been asked again Validate Ip address Regexp. I would use a module such as Regexp::Common.

Sample of code from the Validate Ip address Regexp given by neilwatson

#!/usr/bin/perl use strict; use warnings; use Regexp::Common qw/ net /; my $output = "ae4.5784 up down inet 182.75.123.121/30"; if ( $output =~ m/$RE{net}{IPv4}/ ){ print "match!\n" } __END__ $ perl test.pl match!

Update: See update of fellow Monk haukex above for the correct usage.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: IPAddress check
by AnomalousMonk (Archbishop) on Mar 13, 2018 at 13:53 UTC

    Please note haukex's Update here about using a boundary assertion of some kind. The raw regex  $RE{net}{IPv4} used in the code example here matches the string
        my $output = "ae4.5784     up    down inet     99999.75.123.99999/30";
    which is problematic for containing a valid IP.


    Give a man a fish:  <%-{-{-{-<

      Hello AnomalousMonk,

      Thank you for this minor but important notice. :)

      BR / Thanos

      Seeking for Perl wisdom...on the process of learning...not there...yet!