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

Re: print ip address from string using regex

by roboticus (Canon)
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

flyganji:

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.


Comment on Re: print ip address from string using regex
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://929572]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2014-08-21 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (134 votes), past polls