3

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>
codaddict
  • 445,704
  • 82
  • 492
  • 529
Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498
  • 3
    See http://stackoverflow.com/questions/201323/what-is-the-best-regular-expression-for-validating-email-addresses – McDowell Dec 30 '10 at 09:40

1 Answers1

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

codaddict
  • 445,704
  • 82
  • 492
  • 529