加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用正则表达书实现对页面获取邮箱信息

发布时间:2020-12-14 01:24:11 所属栏目:百科 来源:网络整理
导读:程序:public class TestEmail { public static void main(String[] args) { BufferedReader br = null; try { br = new BufferedReader(new FileReader("g:/test/01.htm")); String str = null; StringBuilder sb = new StringBuilder(); try { while((str=b
程序:public class TestEmail {
public static void main(String[] args) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("g:/test/01.htm"));
String str = null;
StringBuilder sb = new StringBuilder();
try {
while((str=br.readLine())!=null){
sb.append(str);
}
List<String> es = getEmail(sb.toString());
for(String e:es){
System.out.println(e);
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if(br!=null)
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}

}
public static List<String> getEmail(String str){
List<String> es = new ArrayList<String>();
Pattern p = Pattern.compile("[w.-]*w+@[w.-]*w+.w{2,5}");
Matcher m = p.matcher(str);
while(m.find()) {
es.add(m.group());
}
return es;
}


}

实验结果:

shelly726@Gmail.com zach8925@gmail.com 814170056@pp.com zach8925@gmail.com 814170056@pp.com 1064100209@qq.com haosy2007@163.com(部分结果)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读