Emmm... So do you want to do it in 1 line or your just want to try
on ? For me, it seems quite non-effective & impossible with one line...
but breaking them into pieces, that becomes handy. I use this :
my $ip = $ENV{REMOTE_ADDR};
my $error = 0;
my @seg = split /\./, $ip;
$error = 1 unless ($#seg ==3);
# or (scalar(@seg)== 4), this check Format error
foreach my $num(@seg) # Checking on each segment
{
$error = 1 if ($num < 0 or $num > 255 or $num =~ /[^\d]/)
# first 2 condition checking the range.
# =~ /[^\d]/ means, if found any non digit char.
}
print $error;
# basically like this, but, perhaps you don't want some subnet
# mask or localhost or local lan ips... so you can continue
# like this :
$error = 1 if ($ip =~ /^0|255|192|127\..+$/);
# And you can add up some more ...
Refer to some existed modules may much helpful too.
Rgds,
Connie
----- Original Message -----
From: "alex chen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, August 18, 2002 11:14 PM
Subject: how to make a regex for a ip address
> hi,
> i am a beginners in perl.i am studying perl regex now ,and i want to know
> how to make a regex for a ip address.
>
> thank you!!
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]