title: why does my javascript regex.test() give alternating results
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>
  
  
  
  <pre><code>var r = /\d/g;
  var a = r.test("1"); // will be true
  var b = r.test("1"); // will be false
  console.log(a == b); // will be false
  </code></pre>
  
  <p>Please explain to me why the result of <code>r.test("1")</code> alternates with each call?</p>
  
  <p>I was able to work around the issue I was having by removing the g modifier. However I would still like to understand why this happens.</p>