`
XiAoOMAn07
  • 浏览: 74765 次
  • 性别: Icon_minigender_1
  • 来自: 温州
社区版块
存档分类
最新评论

正则表达式 雏形1.

阅读更多
/*
 * import java.io.BufferedReader;
 * import java.io.File;
 * import java.io.FileReader;
 * import java.io.IOException;
 * import java.util.regex.Matcher;
 * import java.util.regex.Pattern;
*/
import java.io.*;
import java.util.regex.*;
public class XiAoOMAn {

public static void main(String[] args) throws IOException{
  
  
	String s; 
	//网页文件位置
   String html = "D:\\index.html";
   
   FileReader fr = new FileReader(new File(html));
   //创建输入
   BufferedReader br = new BufferedReader(fr);
   //创建文本
   FileOutputStream fos = new FileOutputStream("D:\\XiAoOMAn\\GuPiao.txt");
   //创建输出流
   OutputStreamWriter ows = new OutputStreamWriter(fos);
   //匹配标签
   Pattern p = Pattern.compile("((?<=\">)(\\w*?)).*?(?=((</a><label>)|(</th><td>)))");
   String str = null;
   System.out.print("板块       ");
   ows.write("板块       ");
   ////读取html内容 匹配 输出
   while ((str = br.readLine()) != null) {
   //match
    Matcher m = p.matcher(str);
    //提取
    while(m.find()){
    	s = String.valueOf(m.group());
    	//文档输出
    	ows.write(s + "	");
    	
     System.out.print(m.group() + "      ");
    }  
   
   }
   ows.close();
   fos.close();
   br.close();

}

}
分享到:
评论
2 楼 XiAoOMAn07 2009-09-26  
D:\\index.html
teaofnit 写道
类名不要随便取,要有意义。算法不要写在main()里面。
需要有类注释。


恩,会改进的。
1 楼 teaofnit 2009-09-25  
类名不要随便取,要有意义。算法不要写在main()里面。
需要有类注释。

相关推荐

Global site tag (gtag.js) - Google Analytics