How to capture multiple repeated groups?
<p>I need to capture multiple groups of the same pattern. Suppose, I have the following string:</p>
<pre><code>HELLO,THERE,WORLD
</code></pre>
<p>And I've written the following pattern</p>
<pre><code>^(?:([A-Z]+),?)+$
</code></pre>
<p>What I want it to do is to capture every single word, so that Group 1 is : &quot;HELLO&quot;, Group 2 is &quot;THERE&quot; and Group 3 is &quot;WORLD&quot;. What my regex is actually capturing is only the last one, which is &quot;WORLD&quot;.</p>
<p>I'm testing my regular expression <a href="http://regexr.com" rel="noreferrer">here</a> and I want to use it with Swift (maybe there's a way in Swift to get intermediate results somehow, so that I can use them?)</p>
<p>UPDATE: I don't want to use <code>split</code>. I just need to now how to capture all the groups that match the pattern, not only the last one.</p>