Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: regular expression assistance

by markkawika (Monk)
on May 09, 2008 at 22:02 UTC ( [id://685782]=note: print w/replies, xml ) Need Help??


in reply to regular expression assistance

I think perhaps you mean:
next unless $hfileline =~/^\S*\s+$hNames/;
You want to match a "hosts" line where you have an IP (\S*) followed by whitespace (\s+) followed by the hostname. Perhaps a better regex would be:
next unless $hfileline =~/^[\d.]+\s+$hNames/;
To force matches against real lines, and not match against commented-out entries. Another way to match an IP address without using "<= 255" is:
if( $vmServerIP =~ m/^(?:(?:\d|[1-9]\d|1\d\d|2(?:[0-4]\d|5[0-5]))\.){3 +}(?:\d|[1-9]\d|1\d\d|2(?:[0-4]\d|5[0-5]))/ ){

Replies are listed 'Best First'.
Re^2: regular expression assistance
by notasaint (Initiate) on May 09, 2008 at 22:14 UTC

    Great information. Thank you very much!

    -nas

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-09-10 02:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.