I have a password strength regex, apparently there is a different behavior using same regex steing, but different way to create it.
So i have one regex using slash slash closing / / And the other one is using new RegExp(string)
var password ="Password123";
var regex1 = new RegExp("((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^\da-zA-Z]).{6,})");
var regex2 = /((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^\da-zA-Z]).{6,})/;
var result1 = regex1.test(password);
var result2 = regex2.test(password);
document.getElementById("result1").innerHTML = result1;
document.getElementById("result2").innerHTML = result2;
https://jsfiddle.net/hansyulian/cnxzj262/
result1
is true
, which is wrong, while result2
is false
which is correct
Anyone have idea what happened? Is this a bug?