Regex to add a space after each comma in Javascript

前端 未结 8 1460
我寻月下人不归
我寻月下人不归 2021-02-05 10:39

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?

8条回答
  •  醉话见心
    2021-02-05 11:26

    Another simple generic solution for comma followed by n spaces:

    "1,2, 3,   4,5".replace(/,[s]*/g, ", ");
    > "1, 2, 3, 4, 5"
    

    Always replace comma and n spaces by comma and one space.

提交回复
热议问题