title: Best way to store JS Regex capturing groups in array?
body: <p>Exactly what title asks. I'll provide some examples while explaining my question.</p>
  
  <p>Test string: </p>
  
  <pre><code>var test = "#foo# #foo# bar #foo#";
  </code></pre>
  
  <p>Say, I want to extract all text between <code>#</code> (all <code>foo</code>s but not <code>bar</code>).</p>
  
  <pre><code>var matches = test.match(/#(.*?)#/g);
  </code></pre>
  
  <p>Using <code>.match</code> as above, it'll store all matches but it'll simply throw away the capturing groups it seems.</p>
  
  <pre><code>var matches2 = /#(.*?)#/g.exec(test);
  </code></pre>
  
  <p>The <code>.exec</code> method apparently returns only the first result's matched string in the position <code>0</code> of the array and my only capturing group of that match in the position <code>1</code>.</p>
  
  <p>I've exhausted SO, Google and MDN looking for an answer to no avail.</p>
  
  <p>So, my question is, is there any better way to store only the matched capturing groups than looping through it with <code>.exec</code> and calling <code>array.push</code> to store the captured groups?</p>
  
  <p>My expected array for the test above should be:</p>
  
  <pre><code> [0] =&gt; (string) foo
   [1] =&gt; (string) foo
   [2] =&gt; (string) foo
  </code></pre>
  
  <p>Pure JS and jQuery answers are accepted, extra cookies if you post JSFiddle with <code>console.log</code>. =]</p>