问题
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.com
<a href="mailto:my.email@mycompany.com"> my.email@mycompany.com </a>
回答1:
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
来源:https://stackoverflow.com/questions/4561464/detect-emails-in-a-text-and-surrond-it-with-the-a-tag