本文介绍了检测文本中的电子邮件,并使用< a>标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

greetings all
我有一个文本可能包含电子邮件
,我想检测任何电子邮件的发生,并用< a> 标签
例如:

greetings allI have a text that may contains emailsand I want to detect any email occurrence and surround it with the < a > tagex:

my.email@mycompany.com
<a href="mailto:my.email@mycompany.com"> my.email@mycompany.com </a>


推荐答案

使用正则表达式从你可以做:

Using the regex from regular-expression.info you can do:

text = text.replaceAll("(?i)\\b([A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4})\\b",
                       "<a href=\"mailto:$1\"> $1 </a>");

这篇关于检测文本中的电子邮件,并使用&lt; a&gt;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:14
查看更多