在String中查找电子邮件 [英] find emails in a String

查看:135
本文介绍了在String中查找电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从字符串中获取电子邮件,例如:

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

*** test@gmail.com&& ^ test2@gmail.com((&;

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.

我怎样才能得到所有?

推荐答案

尝试

    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());
    }

这篇关于在String中查找电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆