日期:2014-05-20 浏览次数:20722 次
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class URLReg {
public static void main(String[] args) throws Exception
{
URL url = new URL("http://bbs.csdn.net/topics/390017356");
//创建连接
URLConnection conn = url.openConnection();
BufferedReader reader =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
//匹配邮箱规则
String reg = "[a-zA-Z0-9_]+@[a-zA-Z0-9]+(\\.[a-zA-Z]+){1,3}";
String line = "";
Pattern p = Pattern.compile(reg);
while((line=reader.readLine())!=null)
{
Matcher m = p.matcher(line);
while(m.find())
{
System.out.println(m.group());
}
}
}
}