title: Google Apps Script Regex exec() returning null
body: <p>When I run the code below in debug mode I get the expected value on the first iteration of the for loop but null on the second as seen on the images:</p>
  
  <p><strong>First iteration:</strong>
  <img src="https://i.stack.imgur.com/C1rgE.png" alt="enter image description here"></p>
  
  <p><strong>Second iteration:</strong>
  <img src="https://i.stack.imgur.com/YCAXe.png" alt="enter image description here"></p>
  
  <p><strong>What am I dong wrong?</strong></p>
  
  <p>The code I am using is:</p>
  
  <pre><code>var newer_than = ' newer_than:2d'; //added for faster debugging
  var subjectIdentifier = '"Ingress Portal Submitted: "';
  var searchString = 'subject:'+subjectIdentifier+newer_than;
  
  function getPortalName(string) {
    var myRegexp = /: (.+)/g;
    var match = myRegexp.exec(string);
    var portalName = match[1];
    return portalName;
  }
  
  function getPortalsSubmitted() {
    var threads = GmailApp.search(searchString);
    for (i=0; i&lt;threads.length; i++) {
      var subject = threads[i].getFirstMessageSubject();
  
      var portalName = getPortalName(subject);
      var subDate = threads[i].getMessages()[0].getDate();
  
      Logger.log([portalName,subDate]);
    }
  }
  
  function updatePortals() {
    var threads = GmailApp.search('subject:"Ingress Portal"');
    for (i=0; i&lt;threads.length; i++) {
      Logger.log(threads[i].getFirstMessageSubject());
    }
  }
  </code></pre>