Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java email extraction regular expression?

I would like a regular expression that will extract email addresses from a String (using Java regular expressions).

That really works.

like image 845
EugeneP Avatar asked Feb 12 '10 09:02

EugeneP


2 Answers

Here's the regular expression that really works. I've spent an hour surfing on the web and testing different approaches, and most of them didn't work although Google top-ranked those pages.

I want to share with you a working regular expression:

[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})

Here's the original link: http://www.mkyong.com/regular-expressions/how-to-validate-email-address-with-regular-expression/

like image 185
EugeneP Avatar answered Oct 21 '22 07:10

EugeneP


I had to add some dashes to allow for them. So a final result in Javanese:

final String MAIL_REGEX = "([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})";
like image 40
thealy Avatar answered Oct 21 '22 06:10

thealy