var str = 'a,b,c,d,'; str = str.replace(/,$/gi, ''); // "a,b,c,d" alert(str);
,$
gi
str.replace(/[,\s;]+$/, ''); // 移除尾部逗號、空白、分號