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: