title: What is the advantage of unroll the loop compared to shorter regex notation with quantified alternatives?
body: <p>Requirement : Two expressions, <code>exp1</code> and <code>exp2</code>, we need to match one or more of both. So I came up with,</p>
  
  <pre><code>(exp1 | exp2)*
  </code></pre>
  
  <p>However in some places, I see the below being used,</p>
  
  <pre><code>(exp1 * (exp2 exp1*)*)
  </code></pre>
  
  <p>What is the difference between the two? When would you use one over the other?</p>
  
  <p>Hopefully a <a href="https://jsfiddle.net/anoopelias/aj9g1w7c/" rel="nofollow">fiddle</a> will make this more clear,</p>
  
  <pre><code>var regex1 = /^"([\x00-!#-[\]-\x7f]|\\")*"$/;
  var regex2 = /^"([\x00-!#-[\]-\x7f]*(\\"[\x00-!#-[\]-\x7f]*)*)"$/;
  
  var str = '"foo \\"bar\\" baz"';
  var r1 = regex1.exec(str);
  var r2 = regex2.exec(str);
  </code></pre>
  
  <p><strong>EDIT:</strong> It looks like there is a difference in behavior between the two apporaches when we capture the groups. The second approach captures the entire string while the first approach captures only the last matching group. See updated <a href="https://jsfiddle.net/aj9g1w7c/1/" rel="nofollow">fiddle</a>. </p>