正则表达式:网页爬虫:从TXT中获取邮箱地址(获取的练习,缺点:一行只能匹配一个)

  1. import java.util.regex.*;  
  2. import java.io.*;  
  3. class L  
  4. {  
  5.     public static void main(String[] args) throws Exception  
  6.     {  
  7.         getMail();  
  8.     }  
  9.     public static void getMail() throws Exception  
  10.     {  
  11.         BufferedReader bufr=new BufferedReader(new FileReader("m.txt"));  
  12.         String line=null;  
  13.         String reg="[a-zA-Z_0-9]+@[a-zA-Z0-9]+(\\.[a-zA-Z]+)+";//"\\w=@\\w+(\\.\\w+)+";  
  14.         Pattern p=Pattern.compile(reg);  
  15.           
  16.         while((line=bufr.readLine())!=null)  
  17.         {  
  18.             Matcher m=p.matcher(line);  
  19.             while(m.find())  
  20.             {  
  21.                 System.out.println(m.group());  
  22.             }  
  23.         }  
  24.   
  25.     }  
  26. }   
posted @ 2013-08-08 18:54  成风魄郎  阅读(368)  评论(0编辑  收藏  举报