> /(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?)/;

> /([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])/)

Wou ! Looks like too many symbols .. Does matching a legal IP worth
a regex 1km long ? I think it's better to match the IP first,
split /\./ it to four digits and check if their combination is legal -
this will allow any sophisticated tests ( for 127.0.0.1 and the like ).

Here's a regex which looks much shorter and flexible to me :

C:\>perl -w
my $line = 'here is a sample with 123.456.123.456 in the middle';
my ($ip) = $line =~ m@((?:\d{1,3}\.){3}\d{1,3})@;
print "[$ip]\n";
^Z
[123.456.123.456]

C:\>



 Regards,
                                          Evgeny
http://geniek.net
---
"and 224.0.1.2 is for SGI's (Silicon Graphics) dogfight application"
                               TCP/IP Illustrated, 12.4 Multicasting


Reply via email to