Positive and Negative Lookahead -

I have a question about this test

The test asks for Use lookaheads in the pwRegex to match passwords that are greater than 5 characters long, and have two consecutive digits.

This is my answer after reading the hints:

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

The test asks for two consecutive digits. The hint suggest /(?=\w{6})(?=\w*\d{2})/ Is the * used inside parentheses to indicate that a certain character follows another (character * character). And, if so, why does it use \w*\d{2} ? Why is \w used ? Can it be \d*\d ? Can you please explain this to me ?

Thank you!

Using a * after a regex character or group indicates “zero or more” of the proceeding. This means \w*\d{2} means zero or more word characters followed by 2 digits.

Thank you! Now I understand it. I thought that * or + where different when used inside a parentheses :sweat_smile:

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