我需要匹配这样的事情:
pid = '0000000001'
redirectUrlMatch = /https:\/\/example.com\/products\/.*?\/pages\/(pid)\/redirect\/(pid)/
assert.equal validator.matches(html, redirectUrlMatch), true
但它失败了,因为我认为pid
不能用于正则表达式
我怎么能这样做?
答案 0 :(得分:1)
似乎你想把pid放到正则表达式中,如下所示
/https:\/\/example.com\/products\/.*?\/pages\/(0000000001)\/redirect\/(0000000001)/
你可以这样做:
pid = '0000000001'
var redirectUrlMatch = new RegExp("https:\/\/example.com\/products\/.*?\/pages\/("+pid+")\/redirect\/("+pid+")");