像这样可以保留p标签:str.replaceAll("(<(\\/?[^Pp].*?)>)", "").replaceAll("[\\s*]+"," ").replaceAll(" ", "");我现在想保留p和img标签
这个还真不容易实现,单独保留p或者img都可以,但是两个条件放一起就不行了。于是我换了一种思路,用了个函数实现了,你看下,代码是python下的:
[]的用法是匹配[]中的任意一个字符,加^是不匹配的意思,你这样写会把以i、m和g开头标签都会过滤掉的