Remove everything in parentheses java using regex

前端 未结 7 1038
忘掉有多难
忘掉有多难 2020-12-16 20:01

I\'ve used the following regex to try to remove parentheses and everything within them in a string called name.

name.replaceAll(\"\\\\(.*\\\\)\"         


        
7条回答
  •  猫巷女王i
    2020-12-16 20:31

    Strings are immutable. You have to do this:

    name = name.replaceAll("\\(.*\\)", "");
    

    Edit: Also, since the .* is greedy, it will kill as much as it can. So "(abc)something(def)" will be turned into "".

提交回复
热议问题