Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

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
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?
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 lurking in the Monastery: (13)
As of 2015-07-30 19:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls