如何提取div标签里的数字呢??
提取出来是这样的:1<br>2<br>3<br>4<br>下面的代码结果错的public static void main(String[] args) {
String startStr="<div>";
String endStr="</div>";
String regEx =startStr+"([^\"']*)"+endStr;
Pattern p = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher("<div>引子1</div> <div>引子2</div> <div>引子3</div> <div>引子4</div>");
while(m.find()){
String go=m.group(0);
System.out.println(go+"<br>");
}
}
提取出来是这样的:1<br>2<br>3<br>4<br>下面的代码结果错的public static void main(String[] args) {
String startStr="<div>";
String endStr="</div>";
String regEx =startStr+"([^\"']*)"+endStr;
Pattern p = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher("<div>引子1</div> <div>引子2</div> <div>引子3</div> <div>引子4</div>");
while(m.find()){
String go=m.group(0);
System.out.println(go+"<br>");
}
}
或者 String regEx = "\\d*(?=</div>)";
转移序列无效(有效值为 \b \t \n \f \r \' \"" \\)
如果知道是这样的格式直接\\d
Exception in thread "main" java.util.regex.PatternSyntaxException: Look-behind group does not have an obvious maximum length near index 10
(?<=<div>.*)\d*(?=</div>)
改为 (? <= <div>.{2})\d*(?= </div>)