Tell us what’s happening:
My regex didn’t pass all of the tests. I’d like to tell you what I did in plain English and compare it to the solution, but please tell me why mine doesn’t work.
Challenge: Use lookaheads in the pwRegex
to match passwords that are greater than 5 characters long, do not begin with numbers, and have two consecutive digits.
My Regex
/^a-z(?=\d{2,})/gi
Must start with a letter
Lookahead to see if there are five or more alphanumeric characters
Lookahead to see if there are 2 consecutive digits.
Solution Regex
/^\D(?=\w{5})(?=\w*\d{2})/
Cannot start with a digit similar result as ^[a-z] in mine
Lookahead for five alphanumeric characters I look for 5 or more.
Lookahead for zero or more alphanumeric characters Haven’t I done similarly by looking for 5 or more alphanumeric characters?
Followed by 2 consecutive digits I look ahead for two consecutive digits
How are they functionally different enough that mine doesn’t pass all the tests.
Your code so far
let sampleWord = "astronaut";
let pwRegex = /^[a-z](?=\w{5,})(?=\d{2,})/gi; // Change this line
let result = pwRegex.test(sampleWord);
bana12
/^[a-z](?=\w{5,})(?=\d{2,})/
/^\D(?=\w{5})(?=\w*\d{2})/
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15
.
Challenge: Positive and Negative Lookahead
Link to the challenge: