Problem with regex lookahead

Tell us what’s happening:
Describe your issue in detail here.
it should be pass the mission what’s the probem?

Your code so far

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

Challenge: Positive and Negative Lookahead

Link to the challenge:

Why do you have astronaut12 as your sampleWord. Do you need to change that? I believe this was astronaut originally.

astronaut doesnt have any two consecutive digits. So that’s just for see the log.

I get it, but it maybe the reason for tests are not passing

i know the reason, but i need some explanation, the reason is there’s no any \w* in second lookahead but why we need that \w* to pass the task? it’s problem for me because i think there’s already \w{6,} so why we need to use \w again??

Lets decipher this part of your regexp

\d{2,} - two ore more consecutive digits
Now lets decipher stuff with w


\w* - zero or more alphanumerics
\d{2} - two ore more consecutive digits
\w*\d{2} - zero or more alphanumerics followed by exactly two consecutive digits

Basically when we are talking about the whole expression:


Consider it like two conditions. First condition in first parenthesis and second condition in the second.
When you are testing some string with it, string should pass both checks.
Makes sense?

1 Like

why there’s second \w* we already write \w{6,}.

your expression consists of two … subexpressions, let’s say

(?=\w{6,}) this one asks: “hey string, iwanna see that you have more than 5 alphanumerics in you”
(?=\w*\d{2}) this one asks:“hey string I also want something. I need you to be bunch of alphanumerics(zero or more) AND 2 digits after them”

To pass the tests your string should provide correct answer to both requests.

1 Like

thank you for your efforts

That was helpful for me, too. Just a couple days ago I was struggling with this regexp stuff. Try to decipher it from time to time, it helps to get better