I think I have two lookaheads, but code still failing

Tell us what’s happening:
Describe your issue in detail here.
I fail on the " Your regex should use two positive lookaheads ." test, but pass all others. As far as I can see I have two ‘lookaheads’ so I don’t understand why my code is failing.

Your code so far

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0

Challenge: Positive and Negative Lookahead

Link to the challenge:

Hi @companyman, I just checked the test source code for this challenge and seems like the test is expecting two lookahead in sequence.

So by having additional tokens in between you are failing the test.
To me this is possibly a limitation of the test implemented, so it’s up to you:
you can consider this done as you are matching all inputs and you have two lookahaeads,
or you can try to come up with another solution.

For reference this is what the test is looking for:

assert(pwRegex.source.match(/\(\?=.*?\)\(\?=.*?\)/) !== null);

So your regex should have a shape of


to satisfy the above test.

Hope this helps.

Thank you for your reply. I’ll try again with the tighter parameters.

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