title: Parsing a function call using python regex
body: <p>I am attempting to parse a function call:</p>
  <pre><code>foo(arg1, arg2 ...)
  </code></pre>
  <p>to match for <code>foo</code>, <code>arg1</code>, <code>arg2</code>.  But the issue I'm having is, <code>arg1</code> may be <code>bar(x1, x2)</code> with commas inside.</p>
  <p>When I use <a href="https://pythex.org" rel="nofollow noreferrer">this tool</a> with <code>([\w]+)\((.*?)\)$</code> as my regex and <code>foo(bar(2,'a'), bas())</code> as my test case, I'm able to capture <code>foo</code> and the entire line of arguments <code>bar(2,'a'), bas()</code>, but I'm not sure how to capture the arguments separately.</p>
  <p>I would like to capture:</p>
  <ul>
  <li><code>foo</code></li>
  <li><code>bar(2,'a')</code></li>
  <li><code>bas()</code></li>
  </ul>
  <p><strong>How do I revise my python regex to capture these argument separately?</strong></p>