我找不到解決這個簡單問題的方法。替換兩個引號
我想更換兩個連續的 '' 或``通過」
Input:
some ``text'' dspsdj
Out:
some "text"
爲什麼:
s.replaceAll("[`{2}'{2}]", "\"")
Out:
some ""text""
???
謝謝
我找不到解決這個簡單問題的方法。替換兩個引號
我想更換兩個連續的 '' 或``通過」
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»
-->
哦,就是這樣,這是一樣的: 「'{2} |」{2}「。謝謝 – myro
@myro:是的,這是一樣的。另請參見[juergen d](http://stackoverflow.com/a/10581012/521799)的答案 –
是的,但是你會得到最快的標記:D – myro