Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: IPAddress check (updated)

by haukex (Archbishop)
on Mar 13, 2018 at 11:46 UTC ( [id://1210806]=note: print w/replies, xml ) Need Help??


in reply to IPAddress check

"is not working" is not really an adequate problem description. Please see I know what I mean. Why don't you?

But take a look at your regular expression: \d{1,3} vs. \d{1-3} - why the difference? One is right, the other is wrong. See perlrequick and perlretut.

Note that even if you fix that, the regular expression will still match invalid IP's like 999.999.999.999. Instead of reinventing the wheel, I'd recommend Regexp::Common::net:

use warnings; use strict; use Regexp::Common qw/net/; my $output = "ae4.5784 up down inet 182.75.123.121/30"; if ( $output =~ /\b$RE{net}{IPv4}\b/ ) { print "There IS an IPAddress in the output string\n"; } else { print "There is NO IPAddress in the output string\n"; }

Update: Added the word boundary \b to the above regex, because otherwise it would have matched something like 1111.1.1.1 (because 111.1.1.1 is a valid IP) or 256.255.255.256 (because 56.255.255.25 matches).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2024-03-28 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found