Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: IPAddress check

by thanos1983 (Parson)
on Mar 13, 2018 at 11:48 UTC ( [id://1210808]=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1210808]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (9)
As of 2024-04-23 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found