1

この単純な問題の解決策を見つけることができません。

2つの連続する''または``を"に置き換えたい。

Input:
    some ``text'' dspsdj
Out: 
    some "text"

なぜ:

   s.replaceAll("[`{2}'{2}]", "\"")
Out:  
   some ""text""  

???

ありがとうございました

4

4 に答える 4

4

あなたはこのようにそれをするべきです:

s.replaceAll("``|''", "\"")

あなたがやろうとしていたかもしれないことはここでこれでした:

s.replaceAll("[`']{2}", "\"")

しかし、それは完全には正しくありません

于 2012-05-14T09:52:12.727 に答える
3
String input = "some ``text'' dspsdj";
String output = input.replaceAll("`{2}|'{2}", "\"");
于 2012-05-14T09:52:41.790 に答える
1

クラスの後にカーディナリティを配置します。

.replaceAll("[`']{2}", "\""));
于 2012-05-14T09:52:58.893 に答える
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»
-->
于 2012-05-14T09:53:40.063 に答える