本帖最后由 田建 于 2012-6-24 07:48 编辑
直接上代码- import java.net.*;
- import java.io.*;
- import java.util.regex.*;
- class RegexTest_2
- {
- public static void main(String[] args)throws Exception
- {
- getMails();
- }
- public static void getMails()throws Exception
- {
- URL url=new URL("http://www.baidu.com/s?wd=%D3%CA%CF%E4%B5%D8%D6%B7&tn=your_pg");
- URLConnection conn=url.openConnection();
- BufferedReader bufr=new BufferedReader(new InputStreamReader(conn.getInputStream()));
- String line=null;
- String mailreg="\\w+@\\w+(\\.\\w+)+";
- Pattern p=Pattern.compile(mailreg);
- while((bufr.readLine())!=null)
- {
- Matcher m=p.matcher(line);
- while(m.find())
- {
- System.out.println(m.group());
- }
- }
- }
- }
复制代码 不知啥问题!
|
|