Positive and Negative Lookahead (?=\D*\d)

Tell us what’s happening:

Your code so far

// let sampleWord = "astronaut";
// let pwRegex = /(?=[a-z]{3,})(?=\d{2})/; // Change this line
// let result = pwRegex.test(sampleWord);

let password = "ab1";
let checkPass = /(?=\w{3,6})(?=\D*\d)/;
console.log(checkPass.test(password)) // logs true

Why the above console statement gives true as my password is of only 2 character and 1 number and the regex check for atleast 3 \w i.e 3 [A-Za-z0-9_] that is satisfied but, the next
(?=\D*\d) it check for zero or more [^0-9] and one number??

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36.

Link to the challenge:


Positive Lookahead (?=\w{3,6})
Assert that the Regex below matches
\w{3,6} matches any word character (equal to [a-zA-Z0-9_])
{3,6} Quantifier — Matches between 3 and 6 times, as many times as possible, giving back as needed (greedy)