var str = 'aaabbbaacc'; var reg = 'a'; var result = str.replace(new RegExp(reg,'g'), ''); console.log(result);
bbbcc
var str = 'aaabbbaacc'; var reg = 'a'; var result = str.replace(new RegExp("^" + reg + "+",'g'), '');
bbbaacc