Positive and Negative Lookahead hint solution

Positive and Negative Lookahead hint solution


Tell us what’s happening:
In this exercise criteria: “Use lookaheads in the pwRegex to match passwords that are greater than 5 characters long and have two consecutive digits.”

The hint has the solution with a 5, should the solution contain a 6 since the match happens at greater than 5?
let pwRegex = /(?=\w{6,})(?=\D*\d{2})/; instead of
let pwRegex = /(?=\w{5,})(?=\D*\d{2})/;

I checked MDN, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
{n , m} Where n and m are positive integers and n <= m . Matches at least n and at most m occurrences of the preceding expression. When m is omitted, it’s treated as ∞.

As always Thank you for your help.

Your code so far

let sampleWord = "astronaut";
let pwRegex = /(?=\w{6,})(?=\d{2})/; // Change this line
let result = pwRegex.test(sampleWord);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.1 Safari/605.1.15.

Link to the challenge:


Good catch. You can easily make this change yourself. Look at CONTRIBUTING if you’re interested.


Yes I am interested in being able to fix.