Alex Rivera | Logout

Regex to add a space after each comma in Javascript

Asked 2011-10-01T15:16:40.863
30

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?

Edit
Report

1 Answer

3

Don't use a regex for this, use split and join.

It's simpler and faster :)

'1,2,3,4,5,6'.split(',').join(', '); // '1, 2, 3, 4, 5, 6'
answered 2011-10-01T18:44:26.933

Your Answer