我找不到这个简单问题的解决方案。
我想用“替换两个连续的''或``。
Input:
some ``text'' dspsdj
Out:
some "text"
为什么:
s.replaceAll("[`{2}'{2}]", "\"")
Out:
some ""text""
???
谢谢
你应该这样做:
s.replaceAll("``|''", "\"")
您可能打算在这里做的是:
s.replaceAll("[`']{2}", "\"")
但这并不完全正确
String input = "some ``text'' dspsdj";
String output = input.replaceAll("`{2}|'{2}", "\"");
将基数放在类之后:
.replaceAll("[`']{2}", "\""));
尝试这个:
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»
-->