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";
In reply to Re: regexp for extracting IP address
by skx
in thread regexp for extracting IP address
by gcazianfnf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |