Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How to print a substring using regex

by ikegami (Patriarch)
on Sep 29, 2006 at 04:10 UTC ( [id://575459]=note: print w/replies, xml ) Need Help??


in reply to How to print a substring using regex

Two common patterns:

my ($substr) = $var =~ /(pattern)/; print $substr, "\n" if defined $substr;
if ($var =~ /(pattern)/) { print "$1\n"; }

Don't forget to put the parens around what you want to capture.

Update: Two common patterns for multiple matches:

my @substrs = $var =~ /(pattern)/g; print "$_\n" foreach @substrs;
while ($var =~ /(pattern)/g) { print "$1\n"; }

Replies are listed 'Best First'.
Re^2: How to print a substring using regex
by Anonymous Monk on Oct 01, 2006 at 03:44 UTC
    Thanks for the responses, it worked like a charm.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-16 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found