f ($ip =~ /^\d[0-254]\.\d[0-254]\.\d[0-254]\.\d[0-254]$/)
incorect way of matching ip address, it will work fore "61.14.95.02", but will not work for "66.18.99.07". The problem here you just trying to match 2 digital number instead of 3 digits. For example using "[]" [aDc] true for "a" but not for "aa", or true for "D" but not for "aDc".
\d => 0 1 2 3 4 5 6 7 8 9 [01]? => match zero or more occurrence of 0 OR 1. [0-4] => 0 1 2 3 4, but not all of them at same time.
now your code: [0-254] => will match 0 1 2 4 5.
alex p wrote:
Hello all,
I have been trying to find a regex to validate IP ranges and found the following:
m{
^ ( \d | [01]?\d\d | 2[0-4]\d | 25[0-5] )
\. ( \d | [01]?\d\d | 2[0-4]\d | 25[0-5] )
\. ( \d | [01]?\d\d | 2[0-4]\d | 25[0-5] )
\. ( \d | [01]?\d\d | 2[0-4]\d | 25[0-5] )
$ # from the Perl Cookbook, Recipe 6.23,
}xo # pages 218-9, as fixed in the 01/00 reprint
can someone explain this REGEX to me
I have done the following but its not working:
if ($ip =~ /^\d[0-254]\.\d[0-254]\.\d[0-254]\.\d[0-254]$/) { print "$ip is valid\n"; } else {print "$ip is invalid\n";} }
TYIA
_________________________________________________________________
There are now three new levels of MSN Hotmail Extra Storage! Learn more. http://join.msn.com/?pgmarket=en-us&page=hotmail/es2&ST=1
_______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs