in reply to Need regexp to pick off second parenthetical item
(I don't like using $& and friends.) (Update: Also, the regex assumes the second parenthetic group has no nested parentheses!)c:\@Work\Perl\monks>perl -wMstrict -le "my $sentto = 'Fred Flintstone (US) (fredf@gmail.com)'; ;; my $captured = my ($first, $second) = $sentto =~ m{ \A (.*) \s+ ([(] [^(]* [)]) \z }xms; ;; if ($captured) { print qq{first '$first' second '$second'}; } else { warn 'parse failed'; } " first 'Fred Flintstone (US)' second '(fredf@gmail.com)'
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need regexp to pick off second parenthetical item
by BillKSmith (Monsignor) on Mar 26, 2017 at 13:19 UTC |