Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I insert a variable into a regex .match() assertion?

I would like to add a variable, 'example', into a regular expression assertion.

const example = Selector('xyz');

await t.expect(getLocation()).match(/^https:\/\/int-.*.example.com\/en\/example\/-\/  ** HERE SHOULD BE INSERTED A VARIABLE, 'example' ** \/$/)

How could I do this?

like image 204
Jakub Sip Avatar asked Oct 16 '22 14:10

Jakub Sip


1 Answers

You can make it using the RegExp Constructor.

like image 156
Artem Avatar answered Oct 21 '22 02:10

Artem