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 |