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
精彩评论