Skip to content

Instantly share code, notes, and snippets.

@kaugesaar
Created April 29, 2015 18:05
Show Gist options
  • Save kaugesaar/5357f5bab75637f4e2f0 to your computer and use it in GitHub Desktop.
Save kaugesaar/5357f5bab75637f4e2f0 to your computer and use it in GitHub Desktop.
Add thousand separators with regex
var budget = "12381298198";
budget.replace(/(^|[^0-9.])([0-9]{4,})/g, function($0, $1, $2) {
return $1 + $2.replace(/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g, "$& ");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment