title: Bug with RegExp in JavaScript when do global search
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2630418/javascript-regex-returning-true-then-false-then-true-etc">Javascript regex returning true.. then false.. then true.. etc</a>  </p>
  </blockquote>
  
  
  
  <p>First of all, apologize for my bad english.</p>
  
  <p>I'm trying to test string to match the pattern, so I has wrote this:</p>
  
  <pre class="lang-js prettyprint-override"><code>var str = 'test';
  var pattern = new RegExp('te', 'gi'); // yes, I know that simple 'i' will be good for this
  </code></pre>
  
  <p>But I have this unexpected results:</p>
  
  <pre class="lang-js prettyprint-override"><code>&gt;&gt;&gt; pattern.test(str)
  true
  &gt;&gt;&gt; pattern.test(str)
  false
  &gt;&gt;&gt; pattern.test(str)
  true
  </code></pre>
  
  <p>Can anyone explain this?</p>