title: Regex. How to get multiple matches from this string?
body: <p>I am using javascript regex.
  Let's say I have the following string:</p>
  
  <pre><code>XXX_1_XXX XXX_2_XXX XXX_3_XXX YYY_1_YYY YYY_2_YYY YYY_3_YYY
  </code></pre>
  
  <p>and I'd like to run a regex and get a result with this pattern:</p>
  
  <pre><code>Match1
  1.    XXX_1_XXX
  2.    YYY_1_YYY
  Match2
  1.    XXX_2_XXX
  2.    YYY_2_YYY
  Match3
  1.    XXX_3_XXX
  2.    YYY_3_YYY
  </code></pre>
  
  <p>I have tried variations of this:</p>
  
  <pre><code>/(XXX_(.)_XXX)(.)*?(YYY_\2_YYY)/g
  </code></pre>
  
  <p>but it stops at the first match only.</p>
  
  <p>Is there any way to do this with regex? or I am better off iterating over it as an array?</p>