Jesus_Maria
Jesus_Maria

Reputation: 1207

Match regex with template in coffeescript

I need to match such thing:

pid = '0000000001'
redirectUrlMatch = /https:\/\/example.com\/products\/.*?\/pages\/(pid)\/redirect\/(pid)/
assert.equal validator.matches(html, redirectUrlMatch), true

But it fails, because how I think pid cant be placed to regex How I can perform this?

Upvotes: 0

Views: 222

Answers (1)

Kerwin
Kerwin

Reputation: 1212

seems you want put pid into the regex as below

/https:\/\/example.com\/products\/.*?\/pages\/(0000000001)\/redirect\/(0000000001)/

you can do this way:

pid = '0000000001'
var redirectUrlMatch = new RegExp("https:\/\/example.com\/products\/.*?\/pages\/("+pid+")\/redirect\/("+pid+")");

Upvotes: 1

Related Questions