in reply to regex for string
use strict; use warnings; my $str = "hello\nworld"; my ($first, $last); $str =~ m/ (?{ $first = substr($str, 0, 1); $last = substr($str, -1) } +) /x; print "first: '$first'; last: '$last'\n";
However note the caveats of (?{ ... }) groups as documented in perlre.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex for string
by saranperl (Initiate) on Aug 18, 2009 at 08:57 UTC | |
by moritz (Cardinal) on Aug 18, 2009 at 09:13 UTC |