0

当要替换的针是变量时,如何使用全局修饰符?

var needle = '/'+key+'/g';
str = str.replace(needle, trans[key]);
4

1 回答 1

3

为此交换你的针:

var needle = new RegExp(key, "g");
于 2012-04-30T14:00:54.330 回答