Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Forked from toolmantim/sepThousands.js
Created June 3, 2010 16:21
Show Gist options
  • Save ELLIOTTCABLE/424090 to your computer and use it in GitHub Desktop.
Save ELLIOTTCABLE/424090 to your computer and use it in GitHub Desktop.
// A Javascript version of Allan Odgaard's thousands separator regex
// http://blog.macromates.com/2007/recursion-in-regular-expressions/
123456789.toString().replace(/(\d{1,3})(?=(\d{3})+(?!\d))/g, '$1,');
// => "123,456,789"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment