title: Regular Expressions: Capture multiple groups using quantifier
body: <p>Consider the following code:    </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;script type="text/javascript"&gt;
  
  var str = '&lt;12&gt; rnbqkb-r Rnbq-b-r ';
  
  var pat1 = new RegExp('^\\&lt;12\\&gt; ([rnbqkpRNBQKP-]{8}) ([rnbqkpRNBQKP-]{8})');
  var pat2 = new RegExp('^\\&lt;12\\&gt; ([rnbqkp RNBQKP-]{8}){2}');
  var pat3 = new RegExp('^\\&lt;12\\&gt; ([rnbqkp RNBQKP-]{8}){2}?');
  
  document.write(str.match(pat1));
  document.write('&lt;br /&gt;');
  document.write(str.match(pat2));
  document.write('&lt;br /&gt;');
  document.write(str.match(pat3));
  
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>which produces</p>
  
  <pre><code>&lt;12&gt; rnbqkb-r Rnbq-b-r,rnbqkb-r,Rnbq-b-r
  &lt;12&gt; rnbqkb-r Rnbq-b-, Rnbq-b-
  &lt;12&gt; rnbqkb-r Rnbq-b-, Rnbq-b-
  </code></pre>
  
  <p>as output.</p>
  
  <p>Why does neither pattern <code>pat2</code> nor <code>pat3</code> capture the first group <code>rnbqkb-r</code>? I would like to capture all groups without having to repeat them explicitly as in pattern <code>pat1</code>.</p>