in reply to print ip address from string using regex
You need to use a group in your regex to capture the match value, as described in perldoc perlre. For example:
use strict; use warnings; my $string='foo bar baz bow'; if ($string =~ /bar(.*)bow/) { print "between bar and bow is '$1'\n"; }
gives me:
$ perl x.pl between bar and bow is ' baz '
...roboticus
When your only tool is a hammer, all problems look like your thumb.
Update: Added quotes in print statement to show that the whitespace is also captured.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: print ip address from string using regex
by flyganji (Initiate) on Oct 04, 2011 at 20:47 UTC |