title: Regex for nested matches
body: <p>Consider the string</p>
  
  <p><code>cos(t(2))+t(51)</code></p>
  
  <p>Using a regular expression, I'd like to match <code>cos(t(2))</code>, <code>t(2)</code> and <code>t(51)</code>. The general pattern this fits is intended to be something like</p>
  
  <p><code>variable or function name + opening_parenthesis + contents + closing_parenthesis</code>,</p>
  
  <p>where <code>contents</code> can be any expression that has an equal number of opening and closing parentheses.</p>
  
  <p>I'm using <code>[a-zA-Z]+\([\W\w]*\)</code> which returns <code>cos(t(2)))+t(51)</code>, which of course is not the desired result.</p>
  
  <p>Any ideas on how to achieve this using regex? I'm particularly stuck at this "equal number of opening and closing parentheses".</p>