Groovy/Java split string on parentheses “(”

前端 未结 5 1904
小鲜肉
小鲜肉 2020-12-09 03:00

I am trying to perform a split similar the following:

println \"Hello World(1)\".split(\"W\");

Output:

[Hello , orld(1)]
         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-09 03:51

    The split method takes a regular expression pattern.

    If you want to split on "just a regular string" you can use Pattern.quote to quote the string first:

    println "Hello World(1)".split(Pattern.quote("("))
    

提交回复
热议问题