just a stab

starts with
any digit(s) = any number of digits or
= 0 or 1 or none(?=can be none but at most 1) followed by any 2 numbers
= 2 followed by number between 0 and 4 followed by any number
= 25 followed by any number between 0 and 5
followed by  "."

the rest is repeat (I think that cookbook regex is crap but anyways)

your regex fails for a number of reasons.
what you have there is looking to match ip in format of    "two digits"."two
digits"."two digits"."two digits".
you regex should be

if($num =~ /^[0-9]\.[0-9]\.[0-9]\.[0-9]$/) this matches
"digit"."digit"."digit"."digit".
so we need to add {} with a range of occurences

if($num =~ /^[0-9]{1,2}\.[0-9]]{3}\.[0-9]]{3}\.[0-9]]{3}$/) this matches
"one or two digits"."three digits"."three digits"."three digits"
I put in the {num,num} just to show how you can adjust this to your needs
for any match

maybe there is some regex guru out there who can add to this or adjust what
I have stated.
But I did test the above and it works just fine.

----- 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