Regex: match only outside parenthesis (so that the text isn't split within parenthesis)?
<p>I have a target string which looks like this:</p>

<pre><code>"foo (foo, foofoo), bar (foobar), foo, bar (barbar, foo), bar, foo"
</code></pre>

<p>and I want:</p>

<pre><code>["foo (foo, foofoo)", "bar (foobar)", "foo", "bar (barbar, foo)", "bar", "foo"]
</code></pre>

<p>by splitting the target at <code>", "</code> <em>only outside the parenthesis</em>. What is the regex to match the commas outside the parenthesis? In my case, nested parenthesis do not appear and I don't have to consider them.</p>

<p>I personally use Python but any language example is fine.</p>

<pre><code>,(?![^(]*\))
</code></pre>

<p>You can use this to split.See demo.This holds true as u said there are no nested <code>()</code>.</p>

<p><a href="https://regex101.com/r/wV5bD0/1" rel="nofollow">https://regex101.com/r/wV5bD0/1</a></p>

python regex