需要从这段html代码中提取表格中的动态数据 如代码中的63、1、62 求问用来匹配的正则表达式该怎么写?
<table class="pane" id="analysis.summary"><tr><td class="pane-header">Total</td><td class="pane-header">High Priority</td><td class="pane-header">Normal Priority</td><td class="pane-header">Low Priority</td></tr><tbody><tr><td class="pane">63</td><td class="pane"><a href="HIGH">1</a></td><td class="pane"><a href="NORMAL">62</a></td><td class="pane">
0
</td></tr></tbody></table>
------解决方案--------------------
希望对你有用
- Java code
public static void main(String[] args) throws Exception { String str = "<td class=\"pane\">63</td><td class=\"pane\"><a href=\"HIGH\">1</a></td><td class=\"pane\"><a href=\"NORMAL\">62</a></td>"; Matcher m = Pattern.compile("<td.*?>.*?([0-9]+).*?</td>").matcher(str); while(m.find()){ System.out.println(m.group(1)); } }
------解决方案--------------------
String ss = "<td class>63</td>";
Pattern p = Pattern.compile("\\>(\\d+)\\<");
Matcher m = p.matcher(ss);
while(m.find()){
System.out.println(m.group(1));
}
简单例子,楼主可以自己酌情修改.