1

我找不到这个简单问题的解决方案。

我想用“替换两个连续的''或``。

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 回答