我无法找到解决这个简单问题的方法。
我想替换两个连续''或``by“。
Input:
some ``text'' dspsdj
Out:
some "text"
为什么:
s.replaceAll("[`{2}'{2}]", "\"")
Out:
some ""text""
???
谢谢
答案 0 :(得分:4)
你应该这样做:
s.replaceAll("``|''", "\"")
您可能打算这样做:
s.replaceAll("[`']{2}", "\"")
但这不完全正确
答案 1 :(得分:3)
String input = "some ``text'' dspsdj";
String output = input.replaceAll("`{2}|'{2}", "\"");
答案 2 :(得分:1)
将基数放在课后:
.replaceAll("[`']{2}", "\""));
答案 3 :(得分:0)
试试这个:
String resultString = subjectString.replaceAll("([\"'`])\\1", "\"");
<强>解释强>
<!--
(["'`])\1
Match the regular expression below and capture its match into backreference number 1 «(["'`])»
Match a single character present in the list “"'`” «["'`]»
Match the same text as most recently matched by capturing group number 1 «\1»
-->