-3

I want to pass the cookie as a variable .

letstr = cookie;
(/\bcookie\b/g).test('having cookie.');
Ivar
  • 4,655
  • 12
  • 45
  • 50

1 Answers1

0

Here you can pass the variable to the regEx

let x = "cookie"; let reg = new RegExp(\\b${x}\\b,'g');

x.test("having cookie");

\b will create /\b this. and let 'g' will be added to the end of the string