[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] REgular Expression for IP address



At 12:14 PM -0700 2/11/00, Mark W. Alme wrote:
>Hello All:
>
>	This might not be the appropriate venue for this question, 
>but heregoes:
>
>	Can anyone help me with a regular expression to pull out 
>numeric IP addresses from a line of text (i.e 192.168.0.2)? I've 
>tried /(\d+)\.(\d+)\.(\d+)\.(\d)/ but to no avail.

What do you mean "to no avail"?   What happened, and what did you 
expect to happen?  An example would be nice.  \d+\.\d+\.\d+\.\d+ will 
work on appropriate input:

#!perl

my $ip = "128.183.128.241";
$ip =~ m/(\d+)\.(\d+)\.(\d+)\.(\d+)/;
print "$1 $2 $3 $4\n";
$ip = "10.0.0.1";
$ip =~ m/(\d+)\.(\d+)\.(\d+)\.(\d+)/;
print "$1 $2 $3 $4\n";
__END__

Works for me.

>
>	Thanks,
>
>Mark
>
>-------------------------------------
>Mark W. Alme
>Bull Goose Loon
>http://www.bustedknuckle.com, your daily ill-fortune
>-------------------------------------
>
># ===== Want to unsubscribe from this list?
># ===== Send mail with body "unsubscribe" to macperl-request@macperl.org

--
Paul Schinder
schinder@pobox.com

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org