Regular Expressions - Positive and Negative Lookahead

Im having a dificulty here, why should I add a “\w*” before \d{2}

let sampleWord = "astronaut";
let pwRegex =  /(?=\w{6})(?=\d{2})/;
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/104.0.0.0 Safari/537.36

Challenge: Regular Expressions - Positive and Negative Lookahead

Link to the challenge:

because you don’t want to impose that the numbers be at the beginning of the string. The two lookaheads are not indipendent, they match from the same position.

1 Like

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