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-.]+$)");
上記のコードは 1 つの電子メールを取得できます。
どうすればすべてを入手できますか?
試す
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()); }
^と$アンカーを削除するだけです。
^
$