-2

Given a text with email addresses I would like to match all the ones that are not wrapped inside an "a" tag. And I can only do it with a regex.

THIS MATCH:

something@something.else

THIS DOES NOT MATCH:

<a href="mailto:someone@example.com?Subject=Hello%20again" target="_top">Send Mail</a>

Anyone? Thanks.

Andrea
  • 91
  • 8

1 Answers1

0

Here's the basics: /<a(?:\s[^>]*)?>[\W\w]*?<\/a>|([a-z]+@[a-z]+\.[a-z]+)/i

You'll get every link and every text email, but only the text email will be grouped. Not sure if that's what you wanted, but I think that's the only way you'll be able to do it with a single regex.

Whothehellisthat
  • 2,072
  • 1
  • 14
  • 14