当前位置:编程学习 > JAVA >>

java中title正则表达式,这个错在哪里在,怎么用正则表达式提取弹性体文档中<title></title>之间的文字

import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; public class test1_20 { public static String ReadData(){ try { FileReader read = new FileReader("D:/data.txt"); BufferedReader br = new BufferedReader(read); String row; while((row = br.readLine())!=null){ System.out.println(row); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e){ e.printStackTrace(); } return null; } public static void main(String[] args) { Pattern p; Matcher m; String title=ReadData(); p=Pattern.compile("<title>.*?</title>"); m=p.matcher(title); while(m.find()){ String str=m.group(); System.out.println("从"+m.start()+"到"+m.end()+"匹配模式子序列"); System.out.println(str); } } }
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,