目次

02 Javascritp正規表現で置換

例1

var str = 'aaabbbaacc';
var reg = 'a';
var result = str.replace(new RegExp(reg,'g'), '');

console.log(result);

結果

bbbcc

例2

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

結果

bbbaacc