利用正则表达式揪出网页中的email地址

来源:互联网 发布:淘宝用户等级划分 编辑:程序博客网 时间:2024/05/19 01:06

完整代码,可运行

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());
  }
 }
}

0 0
原创粉丝点击