\d only matches one digit....here's a way to extract each number from an ip:
use strict;
my( $ip );
print "Enter a string with an IP:";
$ip = <STDIN>;
$ip =~ m/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
print "$1\n";
print "$2\n";
print "$3\n";
print "$4\n";
Or if you just want the ip from the line:
use strict;
my( $ip );
print "Enter a string with an IP:";
$ip = <STDIN>;
$ip =~ m/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/;
print "The ip is: $1\n";
To just make sure what you have is an ip (and only an ip) is:
m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, June 14, 2001 9:12 AM
Subject: regex matching
> i have a basic knowledge of regex but i want to know if there is a
> simpler way to pull patterns out of a line.
>
> if i have a line like:
>
> here is a sample with 123.456.123.456 in the middle.
>
> m/\d\.\d\.\d\.\d/ will match the entire line. is there an easy way to
> get only the ip address?
>
> thanks..
>
> Brian T. Wallace
> Engineer
>
>