Regular Expressions - Positive and Negative Lookahead

Tell us what’s happening:
why this regex work /(?=\w{6})(?=\w*\d{2})/
and why not this work /(?=\w{5,})(?=\w*\d{2})/
can anybody explain

Your code so far

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

Challenge: Regular Expressions - Positive and Negative Lookahead

Link to the challenge:

The instruction: " Use lookaheads in the pwRegex to match passwords that are greater than 5 characters long,…"

In other words, a password should be six or more characters long (the first lookahead is used to find a string consisting of six characters, not five - that is why “12345” doesn’t pass the test, and “123456” passes).

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