java 正则表达式 求解 求代码 急
<tr>
<td class="">10.5.238.184</td>
<td class="">QM_BRK_11</td>
<td class="">NBL.OUT.FILTER.REQ</td>
<td class="">0</td>
</tr>
<tr>
<td class="red">10.5.238.184</td>
<td class="red">QM_BRK_11</td>
<td class="red">NBL.OUT.MSGSERVER.REQ</td>
<td class="red">18753</td>
</tr>
我获得一个页面文件,现在我要过滤,只要class="red"的 比如:<td class="red">10.5.238.184</td>
然后在控制台输出,。求解,能提供代码,
------解决方案--------------------
最土就是这样:
String html = "<tr>\n<td class=\"\">10.5.238.184</td>\n<td class=\"\">QM_BRK_11</td>\n<td class=\"\">NBL.OUT.FILTER.REQ</td>\n<td class=\"\">0</td>\n</tr>\n\n<tr>\n<td class=\"red\">10.5.238.184</td>\n<td class=\"red\">QM_BRK_11</td>\n<td class=\"red\">NBL.OUT.MSGSERVER.REQ</td>\n<td class=\"red\">18753</td>\n</tr>";
Pattern pattern = Pattern.compile("<td class=\"red\">[^<]*</td>");
Matcher matcher = pattern.matcher(html);
while (matcher.find()) {
System.out.println(matcher.group(0));
}
局限性就是td里面不能有其它属性,如果要能智能点,那么就还需要修改。