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>Take a look at the python CSV library: </p>

<p><a href="https://docs.python.org/2/library/csv.html" rel="nofollow">https://docs.python.org/2/library/csv.html</a> (python 2)</p>

<p><a href="https://docs.python.org/3/library/csv.html" rel="nofollow">https://docs.python.org/3/library/csv.html</a> (python 3)</p>

<p>It's a good way of manipulating text files, I have used it for files that have tabs-delimiters \t rather than commas</p>

<p>A similar problem, with some other examples can be found:
<a href="http://stackoverflow.com/questions/20599233/splitting-comma-delimited-strings-in-python?rq=1">Splitting comma delimited strings in python</a></p>

<p>I just tested the code from this page, it seems to be able to split your text into three if you remove the 'Foo(' from the string</p>

python regex