Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^3: Regex for e-mail contacts name

by flexvault (Monsignor)
on Jan 23, 2012 at 20:45 UTC ( #949521=note: print w/replies, xml ) Need Help??

in reply to Re^2: Regex for e-mail contacts name
in thread Regex for e-mail contacts name


You don't say where the data is coming from, so to get your $string to be what you want, you need to escape the '@' signs:

my $string = qq|sean\, "richard" <richard\>, "john +" <john\>, <jack\>|;

For this, I would use 'split': ( tested code, but re-typed from X-Terminal ):

my @email = split(/\,/,$string); for my $var( 0 .. $#email ) { print "$email[$var]\n"; ..... # put additional code here }

Now you have an array that you could use a regex or 'split' again on each element of the array in get the format you want. If the data is coming from disk, it maybe that each email address is on a line terminated with a 'CR'.

Hope this helps.

"Well done is better than well said." - Benjamin Franklin

Replies are listed 'Best First'.
Re^4: Regex for e-mail contacts name
by lothar4ever (Initiate) on Jan 23, 2012 at 20:57 UTC
    thanks for the reply but that is not what i need.
    The string is coming from an incoming email, i don't know what it is. This is why i need a regex, because all email clients send emails with different formats (Outlook uses names, Gmail is plain, Hotmail sends with <>).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://949521]
[tye]: I get an error string but no reason and no context. Like die "Could not read file.\n" but with a stack trace where all of the useful context is stripped.
[thezip]: Heya tye!
[tye]: hey, thezip!
[RonW]: Hi, tye, thezip
[RonW]: I see useless errors liek that from Perl programs, too.
[tye]: well, you certainly don't see strack traces with all of the values removed from Perl.
[thezip]: Howdy RonW. Not in *my* logfiles you won't!
[tye]: and I never claimed anything about 100% on either side.
[RonW]: Presumably because the coders didn't realize that die and warn will append line number and file when the message strings doesn'r end with a line terminator
[tye]: And these are popular and not new python projects.

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2017-09-21 20:23 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (252 votes). Check out past polls.