Created
April 29, 2015 18:05
-
-
Save kaugesaar/5357f5bab75637f4e2f0 to your computer and use it in GitHub Desktop.
Add thousand separators with regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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