利用正则表达式在繁杂的网页中揪出email地址
完整代码,可运行
package WordAnalyse;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EmailSpider {
public static void main(String args[]) {
try {
BufferedReader br = new BufferedReader(new FileReader("C:\\jiajun.txt"));
String str = "";
while((str=br.readLine()) != null) {
parse(str);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void parse(String str) {
Pattern p = Pattern.compile("[\\w[.-]]+@[\\w[.-]]+[\\w]+");
Matcher m = p.matcher(str);
while(m.find()) {
System.out.println(m.group());
}
}
}