Lookaheads challenge question

Warning some spoilers ahead

Hey, I did complete the challenge but I have a question.
on the 2nd request at two consecutive numbers,

(?=\D*\d{2})

why do I have to add \D* (which means anything but a number 0 or more times) and I can’t just do (?=\d{2})
Is it because some passwords are made of two words? that’s the logical thing that comes to my mind .

Your code so far


let sampleWord = "astronaut";
let pwRegex = /(?=\w{6,})(?=\D*\d{2})/; // Change this line
let result = pwRegex.test(sampleWord);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36

Challenge: Positive and Negative Lookahead

Link to the challenge:

the two lookaheads start looking from the same position

with this the two digits can be anywhere

with only this you are limiting where they could be

/(?=\w{6,})(?=d{2})/;

what if it like this is still from anywhere? ( talking about the numbers ) as I understand according to the syntax should be at the end.

but the two lookaheads are looking from the same position
so, the first lookahead is matching 6 or more alphanumeric cahracters, and the second lookahead matches only if the first two of those are digits

What does this mean?

A lookahead does not match a set of characters, it is a zero-width element, what it does is match a point between characters, and look forward to see if the characters after that point corrispond to the pattern inside the lookahead, and the lookahead will say if that point is a match or not