title: Javascript: How to get multiple matches in RegEx .exec results
body: <p>When I run</p>
  
  <pre><code>/(a)/g.exec('a a a ').length
  </code></pre>
  
  <p>I get </p>
  
  <pre><code>2
  </code></pre>
  
  <p>but I thought it should return</p>
  
  <pre><code>3
  </code></pre>
  
  <p>because there are 3 <code>a</code>s in the string, not 2!</p>
  
  <p>Why is that?</p>
  
  <p>I want to be able to search for all occurances of a string in RegEx and iterate over them.</p>
  
  <p>FWIW: I'm using node.js</p>