Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试从字符串中获取电子邮件,例如:
"*** test@gmail.com&&^ test2@gmail.com((& ";
private static Pattern p = Pattern.compile("(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$)");
上面的代码可以收到一封电子邮件。
我怎样才能得到所有?
尝试
String s = "*** test@gmail.com&&^ test2@gmail.com((& "; 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()); }
只需删除^和$锚。
^
$