I need hello,,,,,,,,,,,world
to bee hello,world
I have this but it only replaces 2 mas
s = s.replace(/\,\,/g,',');
How can I replace more than one ma after another with a single ma?
I need hello,,,,,,,,,,,world
to bee hello,world
I have this but it only replaces 2 mas
s = s.replace(/\,\,/g,',');
How can I replace more than one ma after another with a single ma?
Share Improve this question edited Dec 13, 2014 at 16:59 j08691 208k32 gold badges269 silver badges280 bronze badges asked Dec 13, 2014 at 16:58 124697124697 21.9k69 gold badges197 silver badges319 bronze badges 02 Answers
Reset to default 12s = s.replace(/,+/g,',');
A +
in a regular expression means "one or more of the previous thing, in a row." So ,+
means "one or more mas in a row."
Also can use {2,}
to specify match more than 1
s = s.replace(/,{2,}/g, ',');