Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: IPAddress check (updated)

by haukex (Abbot)
on Mar 13, 2018 at 11:46 UTC ( #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"; 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 is a valid IP) or (because matches).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1210806]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2018-04-20 22:49 GMT
Find Nodes?
    Voting Booth?