首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

求正则表达式,该怎么处理

2012-10-25 
求正则表达式需要从这段html代码中提取表格中的动态数据如代码中的63、1、62求问用来匹配的正则表达式该怎么

求正则表达式
需要从这段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));
}

简单例子,楼主可以自己酌情修改.

热点排行