Reputation: 33605
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:
[email protected]
<a href="mailto:[email protected]"> [email protected] </a>
Upvotes: 3
Views: 246
Reputation: 454960
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>");
Upvotes: 1