正则表达式:查找未包含在HTML <a> tag

时间:2016-07-21 10:57:18

标签: html regex

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.

1 个答案:

答案 0 :(得分:0)

以下是基础知识:/<a(?:\s[^>]*)?>[\W\w]*?<\/a>|([a-z]+@[a-z]+\.[a-z]+)/i

您将获得每个链接和每个文本电子邮件,但只会将文本电子邮件分组。不确定这是不是你想要的,但我认为这是你用一个正则表达式做到这一点的唯一方法。