cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
I would like $` to contain "Fred Flintstone (US) " and $& to contain "(fredf@gmail.com)". The regexp I have in there puts " (US) " at the beginning of $&. I understand why this happens, but not how to fix it. I thought about maybe a look-back assertion for a close-paren, but I have some addresses like "Barney Rubble (barneyr@gmail.com)" so I don't think that will work. I'd like to have a regexp that will pick off the parenthetical address for both kinds of senders. Can someone suggest a solution?#!/usr/bin/perl -w use strict; my $sentto = 'Fred Flintstone (US) (fredf@gmail.com)'; $sentto =~ m/\(.+?@.+?\)/; print "First: $`\nSecond: $&"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need regexp to pick off second parenthetical item
by AnomalousMonk (Archbishop) on Mar 26, 2017 at 01:03 UTC | |
by BillKSmith (Monsignor) on Mar 26, 2017 at 13:19 UTC | |
|
Re: Need regexp to pick off second parenthetical item
by tybalt89 (Monsignor) on Mar 26, 2017 at 01:05 UTC | |
by cormanaz (Deacon) on Mar 26, 2017 at 15:10 UTC | |
by AnomalousMonk (Archbishop) on Mar 26, 2017 at 16:24 UTC |