I read related topics, but still unclear. So build a new topic.
Following is the model answer for the task of “Positive and Negative Lookahead”.
let sampleWord = "astronaut";
let pwRegex = /(?=\w{6})(?=\w*\d{2})/;
let result = pwRegex.test(sampleWord);
I understand the following line
/(?=\w{6})(?=\w*\d{2})/
…means that
1 this code should match the value of at least 8 characters or numbers because there are “\w{6}” and “\d{2}”.
2 this code should match the value that ends with 2 numbers because this code ends with “\d{2}”.
However, this code returned true when the variable “sampleWord” is “a12bcd”, that has only 6 characters and numbers in total, and ends not with numbers.
I tried to figure out on google and FCC topics, but haven’t cleared yet. If anyone tells me its very much appreciated. Thank you.