-1

How can I extract e-mail, from this email:

Email <a href=""mailto:aampianos@aol.com"">aampianos@aol.com</a>

My Regex

(?<=Email)(.*)(?=<\/)

So far I was able to discard word Email and the 'a' closing tag (</a>) to this:

<a href=""mailto:aampianos@aol.com"">aampianos@aol.com

But how can I remove the 'a' opening tag along with href (<a href=""mailto:aampianos@aol.com"">) and only be left with the email?

Thanks

2 Answers2

0

Dont know if this helps but i wont do that with RegEx. would try to split after mailto: and search the next ". Everything between that COULD be an eMailadress.

Martin S.
  • 142
  • 9
0

A real email regex is really complex, see this answer: https://stackoverflow.com/a/201378/2897426

A very simple email validation regex would be

/\S+@\S+\.\S+/

It doesn't work here because the email address is wrapped in text, so you can't use the \S for any non-whitespace character, but you can instead match \w (character, digit or underscore), - and . as "allowed" characters:

/([\w-\.]+@[\w-\.]+\.\w+)/

example: http://regexr.com/3ebl6

keep in mind that me@[127.0.0.1] would be a valid email address, too.

Simon Hänisch
  • 4,740
  • 2
  • 30
  • 42