如何提取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>");
}
}
解决方案 »
- Timpstamp的问题
- 怎样做,帮帮忙!
- 有关String pool 等的几个有关存储区的问题
- JSP报错org.apache.jasper.JasperException: Unable to compile class for JSP: 求教高手
- POI操作excel,如何删除或隐藏一个sheet?
- 问个关于JAVA的变量的问题(我也不知道这个属于那个小区,只好随便找的地方发了。。)
- 如何管理以及维护 开发工具资源库?
- 在servlet里怎么连接oracle数据库
- 如何成为JAVA高手
- 如何让jframe最大化?
- JAVA新手请教一个参数调用传递的问题
- 哈哈~~ 10分钟以后出发去爬“香山”~~
或者 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>)