开发者

Detect emails in a text and surrond it with the <a> tag

greetings all I have a text that may contains emails and I want to detect any email occurrence and surround it with the < a > tag ex:

my.email@mycompany开发者_C百科.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>");            

Ideone Link

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜