Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find emails in a String [duplicate]

Tags:

java

regex

I am trying to get emails from a String which is like:

"*** [email protected]&&^ [email protected]((& ";

private static Pattern p = Pattern.compile("(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$)");

The code above can get one email.

How can I get all?

like image 598
Felix Avatar asked Mar 29 '13 12:03

Felix


1 Answers

try

    String s = "*** [email protected]&&^ [email protected]((& ";
    Matcher m = Pattern.compile("[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+").matcher(s);
    while (m.find()) {
        System.out.println(m.group());
    }
like image 124
Evgeniy Dorofeev Avatar answered Nov 12 '22 21:11

Evgeniy Dorofeev