Java tutorial
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { String s = "stuff1 (foo1(bar1)foo2) stuff2 (bar2) stuff3"; String re = "\\([^()]*\\)"; Pattern p = Pattern.compile(re); Matcher m = p.matcher(s); while (m.find()) { s = m.replaceAll(""); m = p.matcher(s); } System.out.println(s); } }