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 imbibing at the Monastery: (6)
As of 2016-12-07 17:26 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (130 votes). Check out past polls.