Positive Lookahead Regex Javascript

Hello guys. I really don’t understand the logic behind this part. (?=\D*\d)

Your code so far


let sampleWord = "astronaut";
let pwRegex = /(?=\w{5,})(?=\D*\d)/; // 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/98.0.4758.102 Safari/537.36

Challenge: Positive and Negative Lookahead

Link to the challenge:

It’s a positive lookahead ((?=...)) that looks for zero or more non-digits (\D*) followed by a digit (\d).

So your pwRegex is looking for 5 or more word characters with at least one digit.

1 Like

I understand it while i am trying to sleep. Thanks for explanation.

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