in reply to Regexp to match IP address
Where's japhy when you need 'em. :)
dsb
This @ISA my cool %SIG
I guess it kind of depends on how concerned you are with the validity of your data. Testing for 4 1-3 digit numbers seperated by dots is easy:
If you are interested making sure IP's are valid, you could do a couple of things.m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\$/;
One, using the above regex, you could grab the digits and test them individually.
Or you could use a more complicated regex to test for validity during the pattern matching. From O'Reilly's Mastering Regular Expressions:use strict; my @nums; my $IP = "127.0.0.1" (@nums) = $IP =~ m/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; # test each for <= 255 here. # also make sure its not 0.0.0.0
UPDATE: I just realized this was my 150th post. Yay for me. :)m/^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\. ([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$/;
dsb
This @ISA my cool %SIG
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Regexp to match IP address
by kamleein (Initiate) on Mar 26, 2014 at 15:12 UTC |
In Section
Seekers of Perl Wisdom