[英]I can't seem to get replaceAll to work (remove all content between two strings)
因此,我试图删除两个字符串(包括两个字符串)之间的所有内容,但无法弄清楚为什么我的代码无法正常工作。 我什至在以下网站上对其进行了测试: http : //www.regexplanet.com/advanced/java/index.html
他们的“ replaceAll()”部分具有我期望的确切字符串,但是我在Android应用程序中得到的是没有更改的整个原始字符串。 我根据此站点上的示例尝试了不同的方法,例如:
String thematch = Pattern.quote("<p>Listen") + "(.*?)" + Pattern.quote("</audio></p>");
String thenew = thecontent.replaceAll(thematch, "");
和:
String thenew = thecontent.replaceAll("<p>Listen(.*?)</audio></p>","");
都不替换字符串。 这是怎么回事?
编辑:通过将(?s)添加到match的开头进行修正,如anubhava所说。
您需要s
可以匹配s
标记(DOTALL) .
换行符还:
String thematch = "(?s)" + Pattern.quote("<p>Listen") + "(.*?)" + Pattern.quote("</audio></p>");
但是请注意,您应该使用HTML / XML解析器来处理HTML文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.