Looking for guidance on how to effectively use a variable in a regular expression with JavaScript.
I attempted this approach:
var regex = new RegExp('/^' + name + '/');
var result = cookie.name.match(regex);
However, when I debug the 'regex' variable, I get:
/\/^foobar\//
Just to clarify, I am trying to match a cookie named foobar_xxxxxxxx
Why does such a seemingly simple task turn out to be so complex? I have come across many other queries about this issue, but none of the solutions seem to work in my scenario.