因为还没有学网络,所以就在一个文件中寻找符合规则的邮箱
import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class demo2 {
public static void main(String[] args)throws Exception {
BufferedReader bufr=new BufferedReader(new FileReader("e:\\mail.txt"));
String line=null;
String regex="[a-zA-Z0-9_]+@[a-zA-Z0-9_]+(\\.[a-zA-Z]+){1,3}";
Pattern p=Pattern.compile(regex);
while((line=bufr.readLine())!=null)
{
Matcher m=p.matcher(line);
while(m.find())
{
System.out.println(m.group());
}
}
}
}