一个用java正则表达式实现的爬取网页上的email地址的小程序
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.util.regex.*; public class Test { public static void main(String[] args) throws Exception{ BufferedReader bufferedReader=new BufferedReader(new FileReader("email.htm")); String line=""; while((line=bufferedReader.readLine())!=null){ parase(line); } } private static void parase(String line){ Pattern p=Pattern.compile("[\\w[.-]]+@[\\w[.-]]+\\.[\\w]+"); Matcher m=p.matcher(line); while(m.find()){ System.out.println(m.group()); } } }