I'm fairly new to regular expressions and I'm trying to compare two strings together using regex as a place holder/wildcard for certain values that can change in the string that I'm not concerned with. However, if I implement the following code:
var regex = /my .* is/;
var str1 = "Hello, my name is... not important.";
var str2 = "Hello, " + regex + "... not important.";
var result = str1 === str2;
console.log(str1);
console.log(str2);
console.log(result);
I would expect the return to be:
"Hello, my name is... not important."
"Hello, my name is... not important."
true
Instead I get this:
"Hello, my name is... not important."
"Hello, /my .* is/... not important."
false
Can anyone enlighten me as to what's going on and how I might fix it?