title: RegExp.exec() returns NULL sporadically
body: <p>I am seriously going crazy over this and I've already spent an unproportionate amount of time on trying to figure out what's going on here. So please give me a hand =)</p>
  <p>I need to do some RegExp matching of strings in JavaScript. Unfortunately it behaves very strangely. This code:</p>
  <pre><code>var rx = /(cat|dog)/gi;
  var w = new Array(&quot;I have a cat and a dog too.&quot;, &quot;There once was a dog and a cat.&quot;, &quot;I have a cat and a dog too.&quot;, &quot;There once was a dog and a cat.&quot;,&quot;I have a cat and a dog too.&quot;, &quot;There once was a dog and a cat.&quot;,&quot;I have a cat and a dog too.&quot;, &quot;There once was a dog and a cat.&quot;,&quot;I have a cat and a dog too.&quot;, &quot;There once was a dog and a cat.&quot;,&quot;I have a cat and a dog too.&quot;, &quot;There once was a dog and a cat.&quot;,&quot;I have a cat and a dog too.&quot;, &quot;There once was a dog and a cat.&quot;);
  
  for (var i in w) {
      var m = null;
      m = rx.exec(w[i]);
      if(m){
          document.writeln(&quot;&lt;pre&gt;&quot; + i + &quot;\nINPUT: &quot; + w[i] + &quot;\nMATCHES: &quot; + m.slice(1) + &quot;&lt;/pre&gt;&quot;);
      }else{
          document.writeln(&quot;&lt;pre&gt;&quot; + i + &quot;\n'&quot; + w[i] + &quot;' FAILED.&lt;/pre&gt;&quot;);
      }
  }
  </code></pre>
  <p>Returns &quot;cat&quot; and &quot;dog&quot; for the first two elements, as it should be, but then some <code>exec()</code>-calls start returning <code>null</code>. I don't understand why.</p>
  <p>I posted a Fiddle <a href="http://jsfiddle.net/cpak/Wgnns/3/" rel="noreferrer">here</a>, where you can run and edit the code.</p>
  <p>And so far I've tried this in Chrome and Firefox.</p>