Regular Expressions - Positive and Negative Lookahead

Tell us what’s happening:

This lesson requires you to write a regex using that matches strings with more than five characters and have two consecutive digits by using lookaheads. In the second lookahead, why do I need to specify a non-digit (in this case, the \D character class)?

Your code so far

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

Challenge Information:

Regular Expressions - Positive and Negative Lookahead

Welcome to the forum

The first lookahead only checks if there are more than 5 characters.
So, the not d is for the letters and the d and d+ is for two or more consecutive numbers.

Please delete this topic as full solutions are not allowed in the forum.

1 Like

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