title: Regular Expression for formatting numbers in JavaScript
body: <p>I need to display a formatted number on a web page using JavaScript. I want to format it so that there are commas in the right places. How would I do this with a regular expression? I've gotten as far as something like this:</p>
  
  <pre><code>myString = myString.replace(/^(\d{3})*$/g, "${1},");
  </code></pre>
  
  <p>...and then realized this would be more complex than I think (and the regex above is <strong>not even close</strong> to what I need). I've done some searching and I'm having a hard time finding something that works for this.</p>
  
  <p>Basically, I want these results:</p>
  
  <ul>
  <li>45 becomes 45 </li>
  <li>3856 becomes 3,856</li>
  <li>398868483992 becomes 398,868,483,992</li>
  </ul>
  
  <p>...you get the idea.</p>