in reply to regexp for extracting IP address

Your problem appears to be the range that you are using - instead of using a character range you're trying to match against an invalid '2-5' + 5'.

Instead use '[0-9]+' to match against one or more numerical digits.

The following code matches against your input:

my $input = "netaddr 10.1.4.43 Internet Address True"; my $ipaddress = "unknown"; if ( $input =~ /([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ ) { $ipaddress = $1; } print $ipaddress . "\n";
Steve
---
steve.org.uk

Replies are listed 'Best First'.
Re^2: regexp for extracting IP address
by cLive ;-) (Prior) on Oct 11, 2004 at 21:53 UTC
    Simplify and lock down a little further:
    /(?:\d{1,3}\.){3}\d{1,3}/;
    This covers 256-999 as well, but is pretty much what you need in most instances.

    cLive ;-)