Help with regexp replacing every second comma in the string

前端 未结 6 647
暖寄归人
暖寄归人 2020-12-19 04:36

I have a string of that displays like this....

1235, 3, 1343, 5, 1234, 1

I need to replace every second comma with a semicolon

i.e.

1235, 3;

6条回答
  •  难免孤独
    2020-12-19 05:15

    var s = '1235, 3, 1343, 5, 1234, 1';
    var result = s.replace(/(,[^,]*),/g,"$1;");
    

提交回复
热议问题