Regular Expression: Lookahead

Tell us what’s happening:
Hi guys, I’m stuck in this question. This pattern accepts all including “12345”, which it should not. Now I know it does accepts it when I dry run it on a page, but I can’t figure out any other solutions. I try to remove this and end up screwing other testing patterns.

Kindly help or enlighten my mistake so I can correct it.

Your code so far


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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0.

Challenge: Positive and Negative Lookahead

Link to the challenge:

the string should be longer than 5 characters, you need a pattern with that condition

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