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(部分结果)
原文链接:https://www.f2er.com/regex/360676.html