用正则 提取 EMAIL 地址

iinbase 2011-05-03 05:49:32
我现在需要在一个字符串 如下程序 提取出 各个email 地址, 但调了好久
不太懂, 请各位大虾帮忙一下
谢谢

String str1 = "address :is \"From\" \"dummy@dummyxyz.com\", address :is \"From\" \"emilychewpccw@gmail.com\"";

String regEx = ".\"From\"\\s\""; //这个需要各位大虾帮忙修改的地方

Pattern pattern = Pattern.compile(regEx);
Matcher mather = pattern.matcher(str1);

boolean flag = mather.matches();

while (mather.find()) {
// System.out.println( mather.group() );
}

String[] strs = str1.split(regEx);
for (String s : strs) {
System.out.println(s);

}


我现在运行的效果:
address :is
dummy@dummyxyz.com", address :is
emilychewpccw@gmail.com"


目标结果是:
dummy@dummyxyz.com
emilychewpccw@gmail.com"
...全文
101 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ade子夜 2011-05-04
  • 打赏
  • 举报
回复
在网上搜一下好了
  • 打赏
  • 举报
回复

String str1 = "address :is \"From\" \"dummy@dummyxyz.com\", address :is \"From\" \"emilychewpccw@gmail.com\"";

String regEx = "address :is \"From\""; //这个需要各位大虾帮忙修改的地方

Pattern pattern = Pattern.compile(regEx);
Matcher mather = pattern.matcher(str1);

boolean flag = mather.matches();

while (mather.find()) {
// System.out.println( mather.group() );
}

String[] strs = str1.split(regEx);
for (String s : strs) {
System.out.println(s);

}
蛋黄车 2011-05-04
  • 打赏
  • 举报
回复
重复造轮子不如网上搜搜来的快
iinbase 2011-05-04
  • 打赏
  • 举报
回复
但是如果 是 @后面 有几个. 呢?
比如 XX@XXX.com.cn @yyy.xxx.net.cn 等
kString 2011-05-04
  • 打赏
  • 举报
回复
用楼上的方法好些。如果按照楼主的思路来需要匹配的字符有
address :is \"From\" \"
\", address :is \"From\" \"
\"
很难匹配啊
sun0322 2011-05-03
  • 打赏
  • 举报
回复

String str1 = "address :is \"From\" \"dummy@dummyxyz.com\", address :is \"From\" \"emilychewpccw@gmail.com\"";

String regEx = "[\\w]*@[\\w]*.com"; //这个需要各位大虾帮忙修改的地方


Pattern pattern = Pattern.compile(regEx);
Matcher mather = pattern.matcher(str1);

boolean flag = mather.matches();

while (mather.find()) {
System.out.println( mather.group() );
}

// String[] strs = str1.split(regEx);
// for (String s : strs) {
// System.out.println(s);

// }

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧