Split string based on number of commas
<p>I have a text which is splited with commas.</p>

<p>e.g.:</p>

<pre><code>FOO( something, BOO(tmp, temp), something else)
</code></pre>

<p>It could be that <em>something else</em> contain as well a string with commas...</p>

<p>I would like to split the text inside the brakets of FOO to its elements and then pasrse the elements.</p>

<p>What i do know is that <em>FOO</em> must have two commas.</p>

<p>How could I split the contant of <em>FOO</em> to its three elements?</p>

<p><strong>Remark:</strong> <em>something else</em> could be <em>BOO(ddd, ddd)</em> or simply <em>ddd</em>. I can not assume a simple regex regel of <em>'FOO\(\w+, BOO(\w+, \w+), \w+\)'</em></p>

<p>You may use this regex</p>

<pre><code>,(?=(?:(?:\([^)]*\))?[^)]*)+\)$)
</code></pre>

<p>to split your string in the comas, bot not inside BOO(...)</p>

<p><a href="https://eval.in/657163" rel="nofollow">sample</a></p>

python regex