用正则表达式提取单个页面文件里Email地址的简单实现

来源:互联网 发布:3dsmax2014软件许可证 编辑:程序博客网 时间:2024/05/01 06:26
import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.regex.Matcher;import java.util.regex.Pattern;public class EmailCol {public static void main(String[] args) {BufferedReader buf = null;try {buf = new BufferedReader(new FileReader("e:\\360Downloads\\test.html"));while(buf.readLine() != null){parse(buf.readLine());}} catch (IOException e) {e.printStackTrace();} finally {try {buf.close();} catch (IOException e) {e.printStackTrace();}}}private static void parse(String readLine) {Pattern p = Pattern.compile("[\\w[.-]]+@[\\w[.-]]+[.][\\w]+");Matcher m = p.matcher(readLine);while (m.find()) {System.out.println(m.group());}}}

0 0