title: JavaScript regular expression with global match help needed
body: <p>I'm new to JavaScript and have a question about regular expressions. I have the following code:</p>
  
  <pre><code>var patt3=new RegExp(/(July|August)\s+\d{1,2}(\s|,)\d{4}/g);
  var str3 = "August                               12,1988";
  var match3 = str3.match(patt3);
  document.write(match3.toString() + "&lt;br/&gt;");
  </code></pre>
  
  <p>The output is: August 12,1988</p>
  
  <p>Here is the same code but with the 'g' removed from the end of the RegExp: </p>
  
  <pre><code>var patt3=new RegExp(/(July|August)\s+\d{1,2}(\s|,)\d{4}/);
  var str3 = "August                               12,1988";
  var match3 = str3.match(patt3);
  document.write(match3.toString() + "&lt;br/&gt;");
  </code></pre>
  
  <p>The output becomes: August 12,1988,August,,</p>
  
  <p>From the definitions that I've found on the web, 'g' is supposed to match all occurrences of the patterns. But I'm still kind of confused as to what effect 'g' has on the code.</p>
  
  <p>I would greatly appreciate any clarifications.</p>
  
  <p>Thanks in advance.</p>