标签: javascript typescript
我有变量标签
const label = 'test'
和正则表达式
{ name: /test/i }
我想要的是知道我是否可以在正则表达式中使用变量 label,就像这样
label
{ name: `/${label}/i` }
有可能吗?
答案 0 :(得分:1)
要在正则表达式中使用变量,请使用:
new RegExp(`${label}`, 'i')