正则表达式--抓取email地址

来源:互联网 发布:矩阵的LU分解 编辑:程序博客网 时间:2024/05/22 00:33
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 MainClass {    private static BufferedReader bufferedReader;    public static void main(String[] args) {        try {            bufferedReader = new BufferedReader(new FileReader("D:\\11111.html"));            String line = "";            while ((line=bufferedReader.readLine())!=null) {                parseline(line);            }        } catch (FileNotFoundException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (IOException e) {        // TODO Auto-generated catch block        e.printStackTrace();        }    }    private static void parseline(String line) {        Pattern pattern = Pattern.compile("([\\w[.-]]+@[\\w[.-]]+\\.)(com|net|cn)");        Matcher matcher = pattern.matcher(line);        while (matcher.find()) {            System.out.println(matcher.group());        }    }}
zhanghao163mail@163.com........
0 0
原创粉丝点击