I want to remove all unnecessary commas from the start/end of the string.
eg; google, yahoo,, ,
should become google, yahoo
.
If possible ,google,, , yahoo,, ,
should become google,yahoo
.
I've tried the below code as a starting point, but it seems to be not working as desired.
trimCommas = function(s) {
s = s.replace(/,*$/, "");
s = s.replace(/^,*/, "");
return s;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…