Regex Question, Curricullum Positive and Negative Lookahead

Tell us what’s happening:
Based on the answer I search on the forum, the result is false (it needs to be true) because in this one (?=\d{2}), I need to account for the location of the two consecutive numbers (start, middle, end), so if I change that code to (?=\w*\d{2}) , it becomes true (which is correct)

But if I only use (?=\d{2}) in my Regex as bellow

let pwRegex = /(?=\d{2})/;

the result will be true, also both

let pwRegex = /(?=\w{5,})/;

and

let pwRegex = /(?=^\D)/;

is true, so why true, true, and true combined into false? Can anyone help?


let sampleWord = "bana12";
let pwRegex = /(?=\w{5,})(?=^\D)(?=\d{2})/; // Change this line
let result = pwRegex.test(sampleWord);
console.log(result)

Your browser information:

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

Challenge: Positive and Negative Lookahead

Link to the challenge:

the lookaheads start all to check from same position, two of your lookaheads do not have an anchor, so just search for the pattern somewhere in the string, one instead have an anchor.
You need to consider that all lookaheads search from same position. Once you figure out how to use that, you will amange it.

Ohh, I think I get it, thanks!