title: Why does this RegExp exec cause an infinite loop?
body: <p>I have the following block of code:</p>
  
  <pre><code>var field,
      reg = new RegExp('{{.*?}}', 'i'),
      text = 'This is a string with 1: {{param1}}, 2: {{param2}} and 3: {{param3}} parameters.';
  
  while (field = reg.exec(text)) {
      console.log(field);
  }
  </code></pre>
  
  <p>If I include a <code>g</code> global flag, the loop runs fine. But, if it's not global, surely <code>reg.exec(text);</code> should return <code>null</code> after just the first match and end the <code>while</code> loop?</p>
  
  <p>Trying to understand the reason behind it, if somebody can elaborate I would greatly appreciate it.</p>