链接不是';t已链接


Linking email addresses that aren't already linked

我目前正在将电子邮件地址与以下regex进行匹配(并将其链接为mailto链接):

/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+'.[a-zA-Z]{2,64})/

但是,我不想将以前已经链接的任何内容链接为mailto链接或现有链接(例如index.php?电子邮件=example@example.com)否则链接会像下面这样搞砸:

<a href="mailto:<a href="mailto:example@example.com">example@example.com</a>"><a href="mailto:example@example.com">example@example.com</a></a>

更新

以下是我用来查找电子邮件地址的PHP示例(对不起,我认为这不是必需的):

$input = "example@example.com<br><br><a href='mailto:example@example.com'>test email</a><br><br><a href='mailto:example@example.com'>example@example.com</a>";
$output = preg_replace("/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+'.[a-zA-Z]{2,64})/i", "<a href='mailto:$1'>$1</a>", $input);
//output
<a href="mailto:example@example.com">example@example.com</a><br><br><a mailto:example@example.com'="" href="mailto:&lt;a href=">example@example.com</a>'&gt;test email<br><br><a mailto:example@example.com'="" href="mailto:&lt;a href=">example@example.com</a>'&gt;<a href="mailto:example@example.com">example@example.com</a>

更新2

我还有一个正则表达式问题(如果可能的话)-我还有下面的正则表达式,可以使所有链接都指向一个新窗口,但是,我不希望任何链接到新窗口的mailto-是否可以不指向mailto链接?

$output = preg_replace("/<(a)([^>]+)>/i", "<''1 target='"_blank'"''2>", str_replace('target="_blank"', '', $output));

这个正则表达式怎么样?

/((?<!mailto:|=|[a-zA-Z0-9._%+-])[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.‌​-]+'.[a-zA-Z]{2,64}(?![a-zA-Z]|<'/[aA]>))/