Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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 the leaves swirl about...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2018-07-22 03:31 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (451 votes). Check out past polls.