I’m a little confused at the “Positive and Negative Lookahead” module, namely the example given.
let password = "abc123";
let checkPass = /(?=\w{3,6})(?=\D*\d)/;
checkPass.test(password);
I was wondering why the \D* was necessary in the second positive lookahead and ended up playing with it some more, which made me more confused.
let password = "a1bcdf";
let checkPass = /(?=\w{3,5})(?=\d)/;
console.log(checkPass.test(password)); //returns true
but
let password = "abcd1f";
let checkPass = /(?=\w{3,5})(?=\d)/;
console.log(checkPass.test(password)); //returns false
Why did the second code return false? I simply moved the number somewhere else in the string (namely near the end of the string).