我想替换xx*用x.
我试过了 string.replaceAll("xx*", "x");
但在正则表达式*是特殊的,所以我需要给一个\*
但是给\我一个java我需要给\\
==>最后它应该可以使用 string.replaceAll("xx\\*", "x");
但是当字符串包含xx*上述语句时,替换xx*为失败 x
您必须将replaceAll()调用的结果重新分配给字符串变量 - 该方法返回一个新字符串,而不是修改您调用它的字符串.
不要用replaceAll()!! replace()处理文字字符串时使用:
string = string.replace("xx*", "x");
Run Code Online (Sandbox Code Playgroud)