Mahmoud Saleh
Mahmoud Saleh

Reputation: 33605

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:

[email protected]
<a href="mailto:[email protected]"> [email protected] </a>

Upvotes: 3

Views: 246

Answers (1)

codaddict
codaddict

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>");            

Ideone Link

Upvotes: 1

Related Questions