Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

"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).


In reply to Re: IPAddress check (updated) by haukex
in thread IPAddress check by vasanth.easyrider

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-24 01:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found