public static void main(String[] args) { String regx="http://www[\\.\\w]+"; // String regx="http://\\w+\\.\\w+\\.\\w+"; try { FileReader fr=new FileReader("G:\\1.txt"); BufferedReader br=new BufferedReader(fr); String line; while((line=br.readLine())!=null) { if(line.startsWith("http://www")) { System.out.println(line+"haha"); } if(line.matches(regx)) { System.out.println(line); } }br.close();
} catch (Exception e) { e.printStackTrace(); }}
Java正则表达式与IO流简单练习
最新推荐文章于 2025-08-20 09:04:18 发布
本文介绍了一个使用Java实现的简单程序,该程序通过正则表达式来匹配文本文件中符合特定格式的HTTP网址。它首先定义了一个正则表达式用于匹配以'http://www'开头的网址,并读取指定文件中的每一行内容,如果某一行以'http://www'开头或者匹配预设的正则表达式,则将该行打印出来。
4180

被折叠的 条评论
为什么被折叠?



