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?
Commas separate parts of a sentence into logical elements. Commas have no meaning, but they help us to see the structure and therefore the meaning of the sentence. Put a space after a comma. Do not put a space before a comma.
Use the padEnd() and padStart() methods to add spaces to the end or beginning of a string, e.g. str. padEnd(6, ' '); . The methods take the maximum length of the new string and the fill string and return the padded string. Copied!
"1,2,3,4".replace(/,/g, ', ')
//-> '1, 2, 3, 4'
"1,2,3,4".split(',').join(', ')
//-> '1, 2, 3, 4'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With