Reputation: 21
How could I extract the email part from all of the following strings cases:
"Robert Donhan" <[email protected]>
Robert Donhan <[email protected]>
"Robert Donhan" [email protected]
Robert Donhan [email protected]
Thanks
Upvotes: 2
Views: 116
Reputation: 655189
If you do not necessarily need a regular expression, you could use imap_rfc822_parse_adrlist
or mailparse_rfc822_parse_addresses
to get both the address and the name.
Upvotes: 0
Reputation: 3523
I think this should work:
/(^|\s)<?([a-zA-Z0-9._-]+@[a-zA-Z0-9]+\.[a-zA-Z.]{2,6})>?(\n|\r|\s|$)/
Upvotes: 0
Reputation: 454960
Not completely correct but the following regex mostly works:
[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}
with case insensitive option
Upvotes: 1
Reputation: 25599
Actually, your regex can be simpler. Split(explode) on the string using whitepace, go through each item, and check of "@". Then remove all <
and >
.
Upvotes: 0
Reputation: 25
Could you try with this regex:
([\\w-+]+(?:\\.[\\w-+]+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,7})
Anyway, I suggested this site: TXT2RE
Upvotes: 1