Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一些代码来从字符串中删除括号及其内容,但是这一行无法正常工作:
line.replaceAll("\\Q"+matchp+"\\E", rep);
这应该替换所有找到的组,例如“(组)更多单词”并且正则表达式匹配“(组)”,然后字符串将变为 rep +“更多单词”。但字符串不受影响。报价坏了吗?
replaceAll不就地这样做:
replaceAll
line = line.replaceAll("\\Q"+matchp+"\\E", rep);