Hey Alex,
I jumped a little quick there, the previous post does work but I had a doh
moment and forgot your upper range match could only be 254 at most.
Sorry about that.

if($num =~
/^[0-2][0-5][0-4]\.[0-2][0-5][0-4]\.[0-2][0-5][0-4]\.[0-2][0-5][0-4]$/)
 after each class [] use {num,num} to adjust for a part of the ip not having
a number.

so for example

if($num =~
/^[0-2]{0,1}[0-5][0-4]\.[0-2][0-5][0-4]\.[0-2][0-5][0-4]\.[0-2][0-5][0-4]$/)
matches ip's like these
 "three digit 254 or less"."three digit 254 or less"."three digit 254 or
less"."three digit 254 or less".
or
"two digit 54 or less"."three digit 254 or less"."three digit 254 or
less"."three digit 254 or less"





----- Original Message ----- 
From: "alex p" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, January 12, 2004 11:56 AM
Subject: REGEX help!


> 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

Reply via email to