Why does replaceAll fail with “illegal group reference”?

前端 未结 8 1579
轻奢々
轻奢々 2020-12-01 09:56

I am in need to replace

\\\\\\s+\\\\$\\\\$ to $$

I used

String s = \"  $$\";
s = s.replaceAll(\"\\\\s+\\\\$\\\\$\",\"$$\"         


        
8条回答
  •  不知归路
    2020-12-01 10:51

    This is the right way. Replace the literar $ by escaped \\$ str.replaceAll("\\$", "\\\\\\$")

提交回复
热议问题