title: How do you read this JavaScript regular expression?
body: <pre><code>var pattern = /^0+$/;
  </code></pre>
  
  <p>My guess is this:</p>
  
  <p>"Take a look at both the beginning and the end of the string, and if there's a pattern of one or more zeros at the beginning and the end, then return that pattern."</p>
  
  <p>I'm sure that's wrong, though, because when I run the expression with this string:</p>
  
  <pre><code>var string = "0000009000000";
  </code></pre>
  
  <p>It comes up <code>null</code>.</p>
  
  <p>So what's it really saying? And while I'm asking, what/how does JavaScript consider the beginning, middle and end of a string? </p>
  
  <p><strong>UPDATE #1:</strong> Thanks for the responses! I think I understand this now. My confusion stemmed from the fact that I'm visualizing the string as having a beginning, a middle and an end. Like this:</p>
  
  <p>[beginning][middle][end]</p>
  
  <p>In other words, for the given string above, the following expressions work as I expect them to:</p>
  
  <p><code>/^0+/;</code> returns "000000" (a pattern of one or more zeros at the beginning of the string)</p>
  
  <p>and</p>
  
  <p><code>/0+$/</code>; returns "000000" (a pattern of one or more zeros at the end of the string)</p>
  
  <p><strong>UPDATE #2:</strong> I up-voted all the responses to this point, because they're all helpful, and I compiled the answers into one great big one:</p>
  
  <p>Given the following JavaScript code:</p>
  
  <pre><code>var string = "0000009000000";
  var regExp = /^0+$/; 
  alert(regExp.exec(string));
  </code></pre>
  
  <p>It reads, in part, like this: </p>
  
  <p>"If the exact character(s) followed by the ^ modifier and preceded by the $ modifier in the regular expression are not SIMULTANEOUSLY sitting in the first position(s) of the string AND the last position(s) of the string (i.e., they are not the only character(s) in the string), then return <code>null</code>. Else, return the character(s)."</p>
  
  <p>In other words, let's say the given string is six zeros "000000". This results in a match because the exact same group of "0" characters are sitting in BOTH the first positions (<strong>1st 2nd 3rd</strong> 4th 5th 6th) AND the last positions (1st 2nd 3rd <strong>4th 5th 6th</strong>) of the string.</p>
  
  <p>However, in the original given string, there are six zeros, followed by a nine, followed by six zeros ("0000009000000"). Now, the six zeros in the first positions of the string (1st, 2nd, 3rd, 4th, 5th, 6th) are NOT the exact same six zeros sitting in the last positions of the string (8th, 9th, 10th, 11th, 12th, 13th). Hence, a <code>null</code> is returned.</p>