Regular expression to replace content between parentheses ()

Praneel PIDIKITI picture Praneel PIDIKITI · Apr 12, 2011 · Viewed 16k times · Source

I tried this code:

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

But it returns null. What am I missing?

Answer

Mike Thomsen picture Mike Thomsen · Apr 12, 2011

Try:

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

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