1. (?i) 表示所在位置右侧的表达式开启忽略大小写模式
2. Pattern.CASE_INSENSITIVE | Pattern.DOTALL 进行大小不明感的匹配单行或多行文本
例如:
<div id="content">
<div class="divBlock" id="0.24911554699056548">
<div class="edit-boxfull" data-tooltype="top">
<div class="edit-boxRightIcon">
<i><span class="glyphicon glyphicon-move f16" title="拖动"></span></i>
<i><span class="glyphicon glyphicon-edit f16" title="编辑"></span></i>
<i><span class="glyphicon glyphicon-file f16" title="复制"></span></i>
<i><span class="glyphicon glyphicon-trash f16" title="删除"></span></i>
</div>
<div class="edit-contentBox">
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="Tem_FullBlock">
<tbody>
<tr>
<td align="left" valign="top" style="padding:10px 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td valign="top" class="Tem_TextContent" style="color:#232425; font-family:Microsoft YaHei; font-size:12px; line-height:1.4; text-align:center; mso-line-height-rule:exactly;">图片无法显示? 请点击 <a href="http://image.izacholsm.com/t/zz?t=D49DE87F-74DB-4B3D-A46C-C71BD5B37923&STARID={{{STARID}}}" style="color:#565656; text-decoration:underline;" target="_blank">在线浏览</a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
去掉内容后显示为:
<div id="content">
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="Tem_FullBlock">
<tbody>
<tr>
<td align="left" valign="top" style="padding:10px 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td valign="top" class="Tem_TextContent" style="color:#232425; font-family:Microsoft YaHei; font-size:12px; line-height:1.4; text-align:center; mso-line-height-rule:exactly;">图片无法显示? 请点击 <a href="http://image.izacholsm.com/t/zz?t=D49DE87F-74DB-4B3D-A46C-C71BD5B37923&STARID={{{STARID}}}" style="color:#565656; text-decoration:underline;" target="_blank">在线浏览</a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
//过滤内部菜单div: "edit-boxfull"
Pattern patternDiv = Pattern.compile("<div class=\"(?i)edit-box(top|left|right|bottom|topblock).*?</div>");
Matcher matcherDiv = patternDiv.matcher(body);
while (matcherDiv.find()) {
body=body.replace(matcherDiv.group(),"");
}
//针对 "divBlock",仅返回"Tem_FullBlock"组合在一起的值
patternDiv = Pattern.compile("(<div\\sclass=\"divBlock((?!divBlock).)*\\/div>)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
matcherDiv = patternDiv.matcher(body);
while (matcherDiv.find()) {
String div=matcherDiv.group();
Pattern patternTable = Pattern.compile("(<table.*class=\"Tem_FullBlock.*</table>)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher matcherTable = patternTable.matcher(div);
if (matcherTable.find()) {
body=body.replace(div,matcherTable.group(1));
}
}