标签: javascript regex
当要更换的针是变量时,如何使用全局修改器?
var needle = '/'+key+'/g'; str = str.replace(needle, trans[key]);
答案 0 :(得分:3)
为此换一针:
var needle = new RegExp(key, "g");