<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_29">
第一行:一些内容<br />
第二行:一些内容<br />
</td></tr></table>
求一个正则表达式。要求:得到里面的文字,这些文字作为一个整体,而不是通过单行匹配得到的。
例如这样"(.*<br />)",就不符合我的要求。
第一行:一些内容<br />
第二行:一些内容<br />
</td></tr></table>
求一个正则表达式。要求:得到里面的文字,这些文字作为一个整体,而不是通过单行匹配得到的。
例如这样"(.*<br />)",就不符合我的要求。
str = str.replaceAll("<script[^>]*>.*</script>", "");
public static void main(String[] args) {
String testStr = "<html><head></head><body><table cellspacing=\"0\" cellpadding=\"0\"><tr><td class=\"t_f\" id=\"postmessage_29\">\n 第一行:一些内容<br />\n 第二行:一些内容<br />\n </td></tr></table></body></html>";
String tableReg = "<table.*?><tr><td class=\"[\\w_]+\" id=\"[\\w_]+\">*.*?</table>";
String contextReg = ">[\r\n\\s]*([^<]+)<br";
Pattern p = Pattern.compile(tableReg, Pattern.DOTALL);
Matcher matcher = p.matcher(testStr);
while (matcher.find()) {
String tablePattern = matcher.group(0);
System.out.println("全体:" + tablePattern);
System.out.println("-------------------------------------------------");
Pattern contextPattern = Pattern.compile(contextReg);
Matcher contextMatcher = contextPattern.matcher(testStr);
while (contextMatcher.find()) {
System.out.println(contextMatcher.group(1));
}
}
}
String text = str.replaceAll(".*<body[^>]*>(.*)</body>.*","$1").replaceAll("<[^>]+>", "");