この単純な問題の解決策を見つけることができません。
2つの連続する''または``を"に置き換えたい。
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»
-->