小编She*_*ger的帖子

Javascript替换函数不能与regexp一起使用

为什么这段代码不能正常工作?

var temp = "@TEMP (A1)"
var text = "1st Oct @TEMP (A1)"
text = text.replace(new RegExp(temp, "gi"), "");
console.log(text); //I get same text even though I used replace instead of 1st Oct??
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释这里出了什么问题吗?

javascript regex replace

1
推荐指数
1
解决办法
209
查看次数

标签 统计

javascript ×1

regex ×1

replace ×1