Positive and Negative Lookhead why to use \D+

what is the use of \D+ in this project? In the challenge it does not tells us to look out for not digit characters then why should we put \D+ in our code? And why is there no need to use \W+ to look for non-alphanumeric characters but we need the \D+. Am I missing something?

Thanks in advance!

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

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.

the two lookaheads look from the same position
the first one says to have at least 5 alphanumeric characters
but the requirments are that a digit can’t be the first character
so the second lookahead say again that there should be one or more non digit characters at the beginning followed by 2 digits
the first lookahead gives the length condition, the second one specific what kind of characters should be there