Search code examples
javaregexstringreplaceall

Regular expression to replace content between parentheses ()


I tried this code:

string.replaceAll("\\(.*?)","");

But it returns null. What am I missing?


Solution

  • Try:

    string.replaceAll("\\(.*?\\)","");
    

    You didn't escape the second parenthesis and you didn't add an additional "\" to the first one.