I want to pass the cookie as a variable .
letstr = cookie;
(/\bcookie\b/g).test('having cookie.');
I want to pass the cookie as a variable .
letstr = cookie;
(/\bcookie\b/g).test('having cookie.');
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