Match e-mail addresses not contained in HTML tag
Posted
by SvartalF
on Stack Overflow
See other posts from Stack Overflow
or by SvartalF
Published on 2010-04-29T01:55:59Z
Indexed on
2010/04/29
2:17 UTC
Read the original article
Hit count: 209
I need to highlight an email addresses in text but not highlight them if contained in HTML tags, content, or attributes.
For example, the string [email protected]
must be converted to <a href="mailto:[email protected]">[email protected]</a>
But email addresses in the string <a href="mailto:[email protected]">[email protected]</a>
must not be processed.
I've tried something like this regexp:
(?<![":])[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}(?!")
but it doesn't work properly.
© Stack Overflow or respective owner