Why String.replaceAll() don't work on this String?

后端 未结 1 418
遇见更好的自我
遇见更好的自我 2021-01-21 06:42
    //This source is a line read from a file 
    String src = \"23570006,music,**,wu(),1,exam,\\\"Monday9,10(H2-301)\\\",1-10,score,\";

    //This sohuld be from a mat         


        
相关标签:
1条回答
  • 2021-01-21 07:08

    ( and ) are regex metacharacter; they need to be escaped if you want to match it literally.

    String group = "\"Monday9,10\\(H2-301\\)\"";
                                ^        ^
    

    The reason why you need two slashes is that because \ in a string literal is itself an escape character, so "\\" is a string of length 1 containing a slash.

    0 讨论(0)
提交回复
热议问题