Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: print ip address from string using regex

by roboticus (Chancellor)
on Oct 04, 2011 at 15:28 UTC ( #929572=note: print w/replies, xml ) Need Help??

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 between bar and bow is ' baz '


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

    Thank you all for help.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://929572]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2017-11-22 05:54 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (315 votes). Check out past polls.