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:

```
myString = myString.replace(/^(\d{3})*$/g, "${1},");

```

...and then realized this would be more complex than I think (and the regex above is **not even close** to what I need). I've done some searching and I'm having a hard time finding something that works for this.

Basically, I want these results:

* 45 becomes 45
* 3856 becomes 3,856
* 398868483992 becomes 398,868,483,992

...you get the idea.