Regular expressions about \w\d\D

The question goes like the following:
“Use lookaheads in the pwRegex to match passwords that are greater than 5 characters long, and have two consecutive digits.”

And here is the answer:

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

Anybody can tell me how the regexes “(?=\w*\d{2})” matches the “two consecutive digits” part? The" \d{2}" means at least two digital character, not two consecutive digits, right? I’m really confused about this. Thanks.

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36

Challenge: Positive and Negative Lookahead

Link to the challenge:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.