我想从一个字符串,就像收到电子邮件:查找电子邮件中的String
"*** [email protected]&&^ [email protected]((& ";
private static Pattern p = Pattern.compile("(^[a-zA-Z0-9_.+-][email protected][a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$)");
上面的代码可以得到一个电子邮件。
我该如何得到所有?
我想从一个字符串,就像收到电子邮件:查找电子邮件中的String
"*** [email protected]&&^ [email protected]((& ";
private static Pattern p = Pattern.compile("(^[a-zA-Z0-9_.+-][email protected][a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$)");
上面的代码可以得到一个电子邮件。
我该如何得到所有?
尝试
String s = "*** [email protected]&&^ [email protected]((& ";
Matcher m = Pattern.compile("[a-zA-Z0-9_.+-][email protected][a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+").matcher(s);
while (m.find()) {
System.out.println(m.group());
}
只需卸下^
和$
锚。
您可以使用模式类在java中 [见这里] [1] [1]:http://stackoverflow.com/questions/7899116/extracting-names-and -email-address-from-string-with-regex – PSR
see here http://stackoverflow.com/questions/7899116/extracting-names-and-email-address-from-string-with-regex – PSR
我不确定电子邮件中允许使用'+'字符。 – sp00m