当我们需要过滤掉字符串中不需要的html标签时,可以使用replaceAll()方法进行过滤,replaceAll()不同于replace()方法,replaceAll()方法可以使用正则表达式作为参数进行匹配,所以比较方便,replaceAll()方法源码如下:
public String replaceAll(String regex, String replacement) {
return Pattern.compile(regex).matcher(this).replaceAll(replacement);
}
使用样例:
public void shouldAnswerWithTrue() {
String htmlStr = "" +
"" +
"这是标题 " +
"" +
"" +
"" +
"div标签" +
"p标签
" +
"" +
"";
String expectScript = htmlStr.replaceAll("


