I have a string like the one given below.
String1 = "a,b,,,c"
I want to replace the commas occuring in the middle with a single comma i.e. remove duplicate values.How would I do it.
I have a string like the one given below.
String1 = "a,b,,,c"
I want to replace the commas occuring in the middle with a single comma i.e. remove duplicate values.How would I do it.
match it 2 or more timesHere is something fairly generic that would work for any repeated string: /(.)(?=\1)/g
If you only want commas, simply use /,(?=,)/g
Replace the result with an empty string.
string1 = string1.replace(/,(?=,)/g, '');