正则表达式去除html的属性contenteditable

Pattern pattern2 = Pattern.compile("(?<=<)[^>]*(contenteditable=(?:\"|'|\\s)*(?:true)(?:\"|'|\\s)*)[^>]*(?=>)");

可以匹配 html标签内部的contenteditable属性 并将匹配到的放入第一个捕获组,方便将该属性替换为空
替换的java代码为:

public String doReplace(String value) {
value = value.replaceAll("\\$", "\\\\\\$");
Matcher match = pattern2.matcher(value);
StringBuffer sb = new StringBuffer();
while (match.find()) {
String result = match.group();
String target = match.group(1);
result = result.replaceAll(target, "");
match.appendReplacement(sb, result);
}
match.appendTail(sb);
value = sb.toString();
value = value.replaceAll("\\\\\\$", "\\$");
return value;
}

猜你喜欢

转载自it-dream-qq-com.iteye.com/blog/2218488
今日推荐