Match function parameters
<p>I've been trying to create a regex that matches function parameters.</p>

<p>Here's the full sample (with debug mode): <a href="https://regex101.com/r/vM7xN1/1" rel="nofollow">https://regex101.com/r/vM7xN1/1</a></p>

<p>The regex I currently have is this one: <code>\(([^,\s\)]+)(?:\s*,\s*([^,\s\)]+))*\)</code></p>

<p>And the match results I'm trying to achieve:</p>

<pre><code>1. someFunc(param) =&gt; ['param']

2. someFunc(param, param2) =&gt; ['param', 'param2']

3. someFunc(param, param2, param3) =&gt; ['param', 'param2', 'param3']

4. someFunc(param, param2, param3, param4) =&gt; ['param', 'param2', 'param3', 'param4']
</code></pre>

<p>For some reason, this matches only 1, 2 functions correcly. And in functions 3 and 4 it will only match the first param and the last param.</p>

<p>Why is it skipping the params between the first and the last?</p>

<p><strong>Edit:</strong>
Additional tests:</p>

<pre><code>'myFunction(param1, param2, param3)'.match(/(([^,\s)]+)(?:\s*,\s*([^,\s)]+))*)/) =&gt; ["(param1, param2, param3)", "param1", "param3"]
</code></pre>

<p>When trying without the non-capturing group I get this:</p>

<pre><code>'myFunction(param1, param2, param3)'.match(/(([^,\s)]+)(\s*,\s*([^,\s)]+))*)/) =&gt; ["(param1, param2, param3)", "param1", ", param3", "param3"]
</code></pre>

<p>Any help would be great.</p>

<p>Thanks!</p>