关于正则表达式的奇怪问题!!
目的:这是一个通过正则表达式把大家留的邮箱,集中输出。但是,这个正则表达式单独测试一个邮箱正确,但是放到这个程序就读不出来邮箱,这是为什么呢?想不明白!请大家帮帮小弟 谢谢!
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 Email {
public static void main(String[] args) {
try {
BufferedReader br=new BufferedReader(new FileReader("D:\workspace\Email\email.html"));//通过输入流读取网页文件信息!
String line="";
while((line=br.readLine())!=null){
pase(line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void pase(String line) {
Pattern p=Pattern.compile("^([a-z0-9A-Z]+[- ¦\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\.)+[a-zA-Z]{2,}$");//判断邮箱的正则表达式
Matcher m=p.matcher(line);
m.matches();
while(m.find()){
System.out.println(m.group());
}
}
}
|