0
"Max Mustermann" <[email protected]>
[email protected]
Max <[email protected]>

I need a regular Expression which matches everthing outside the arrow brackets (including the brackets). The Match should be removed afterwards.

After the replacement it should look like this:

"Max Mustermann" <[email protected]> => [email protected]
  • Although not the same question, note that fully parsing all forms of email addresses is hard, http://stackoverflow.com/questions/46155/validate-email-address-in-javascript. – hlovdal Feb 14 '13 at 11:46

2 Answers2

0

The easiest solution would be to search for

[^<]*<([^>]*)>.*

and replace that with \1 or $1, depending on your regex engine.

This removes everything until the first < and everything from the next > until the end of the string.

Let's just hope that there will be no brackets inside the quoted names.

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
0

This should work, but beware that it is very simplified:

(?:[^<]*<)?([^>]+).*

Answer of email will be in $1.

For example, in Perl use:

$email =~ s/(?:[^<]*<)?([^>]+).*/$1/;

See RegexPlanet online demo.

Community
  • 1
  • 1
mvp
  • 111,019
  • 13
  • 122
  • 148