Tell us what’s happening:
Describe your issue in detail here.
Your code so far
let sampleWord = "astronaut";
let pwRegex = /(?=\w{6})(?=\w*\d{2})/; // Change this line
let result = pwRegex.test(sampleWord);
Isn't \w{6} saying match passwords that are exactly 6 characters long? Why wouldn't greater than 6 characters long be \w{6,} ?
Also, to satisfy the 2 consecutive digits, why is it not just(?=\d{2})? What is this w* stating (?=\w*\d{2})?
The way I read the second half is there can be 0 or more characters with 2 consecutive digits. Doesn't make much sense to me with the w*. Any insight would be greatly appreciated.
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Challenge: Regular Expressions - Positive and Negative Lookahead
That is referring to the second part of my question. What i just wrote prior was referring to the first part of my question. I did read that which is why I’m confused on how it applies to this problem.
Matches the preceding item “x” 0 or more times. in MDN
I wrote in my question, “The way I read the second half is there can be 0 or more characters.” \w*
Just trying to figure out why that needs to be added instead of (?=\d{2})
yes, but regex always match the part of the string that has the pattern. To have a string that has exactly six characters, you need to use anchors to match the beginning and end of the string.
the two lookaheads match the same position and look at the immediately following characters, if you use only this, you are saying that the first two characters matched by the other lookahead must be numbers, instead the numbers can be anywhere