我有一个用例,我想在html字符串中替换一些值,所以我需要为replaceAll做这件事,但那不工作,虽然替换工作正常,这里是我的代码:模式替换字符串中的转义字符失败与replaceAll
String str = "<style type=\"text/css\">#include(\"Invoice_Service_Tax.css\")</style>";
String pattern = "#include(\"Invoice_Service_Tax.css\")";
System.out.println(str.replace(pattern, "some-value"));
System.out.println(str.replaceAll(pattern, "some-value"));
输出为:
<style type="text/css">some-value</style>
<style type="text/css">#include("Invoice_Service_Tax.css")</style>
对于我的使用情况下,我只需要做的replaceAll,我试着用下面的模式,但也没有帮助:
"#include(\\\"Invoice_Service_Tax.css\\\")"
"#include(Invoice_Service_Tax.css)"
这个工作对我来说:) – user2098324