title: Groovy remove text between parentheses in peer and parent child relationship
body: <p>In groovy, how to remove text between parentheses in peer and parent child relationship? Such as <code>a(b(c)d)</code> returns <code>a</code>. And <code>a(b)c(d)</code> returns <code>ac</code>?</p>
  
  <p>Here is my code. But it can only handle one case. not both. </p>
  
  <pre><code>println name.replaceFirst( /\(.*\)/, '' ) 
  println name.replaceAll( /\((.*?)\)/, '' )
  </code></pre>
  
  <p>Another solution is to detect if the parentheses match is peer to peer or parent to child and using the right RegEx. But I don't know how.</p>
  
  <p>Thanks,</p>