java中title正则表达式,这个错在哪里在,怎么用正则表达式提取弹性体文档中<title></title>之间的文字
importjava.io.BufferedReader;importjava.io.File;importjava.io.FileNotFoundException;i...
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);
}
}
} 展开
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);
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询