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?
Those are all good ways but in cases where the input is made by the user and you get a list like "1,2, 3,4, 5,6,7"
..In which case lets make it idiot proof! So accounting for the already formatted parts of the string, the solution:
"1,2, 3,4, 5,6,7".replace(/, /g, ",").replace(/,/g, ", ");
//result: "1, 2, 3, 4, 5, 6, 7" //Bingo!