let item = 't2e';
let str = "这是一个测试字符串,将其中的所有[[item]]替换为哈。";
// 构建正则表达式,并进行全局替换
let replacedStr = str.replace(new RegExp(`\\[\\[${item}\\]\\]`, 'g'), '哈');
console.log(replacedStr);
04-12
2万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-01
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交