I thought that by instantiating a pattern = new RegExp() and passing a string then using .test(value) would be the same as using /^...$/.test(value), but they don't appear to be equal as using RegExp and passing a string fails each time. Is this not correct? On MDN it seems to say that this should work.
SHOULD ALL FAIL AND THEY DO
var str = "7D>";
var res = /^[A-Za-z0-9\d=!\-@._*]*$/.test(str);
console.log(res); // false which is correct
var patt = /^[A-Za-z0-9\d=!\-@._*]*$/;
var res = patt.test(str);
console.log(res); // false which is correct
var patt = new RegExp("/^[A-Za-z0-9\d=!\-@._*]*$/");
var res = patt.test(str);
console.log(res); // false which is correct, but suspicious based on follow results
SHOULD ALL PASS AND THEY DON'T
var str = "7D";
var res = /^[A-Za-z0-9\d=!\-@._*]*$/.test(str);
console.log(res); // true which is correct
var patt = /^[A-Za-z0-9\d=!\-@._*]*$/;
var res = patt.test(str);
console.log(res); // true which is correct
BUT BOTH THESE ATTEMPTS FAIL WHEN THEY SHOULD PASS
var patt = new RegExp("/^[A-Za-z0-9\d=!\-@._*]*$/");
var res = patt.test(str);
console.log(res); // false which is NOT correct
var patt = new RegExp("^[A-Za-z0-9\d=!\-@._*]*$");
var res = patt.test(str);
console.log(res); // ALSO false which is NOT correct
\-in the string you pass tonew RegExpas\\-. Otherwise, put the-at the end of the character set.-at the end to mean no upper bound on the character class.