I have a string that is made up of a list of numbers, seperated by commas. How would I add a space after each comma using Regex?
"1,2,3,4".replace(/,/g, ', ') //-> '1, 2, 3, 4'
"1,2,3,4".split(',').join(', ') //-> '1, 2, 3, 4'
Use String.replace with a regexp.
> var input = '1,2,3,4,5', output = input.replace(/(\d+,)/g, '$1 '); > output "1, 2, 3, 4, 5"