Regular Expressions: Positive and Negative Lookahead - Help

Regular Expressions: Positive and Negative Lookahead - Help
0.0 0

#1

So i’m on --> https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/positive-and-negative-lookahead

I reworked te example and got this answer:

let sampleWord = "99etu";
let pwRegex =/(?=\w{3,6})(?=\D\d{2,})/i; // Change this line
let result = pwRegex.test(sampleWord);
console.log(result)

I don’t get why the point of the \D? Is the pattern only going to work if the other one is present?


#2

\D means no digit like A or J.

Check this thread for more detailed explination


#3

Yeah but why is it in there in the first place? Why cant it just be the pattern of 2 or more numbers?


#4

Well this /(?=\w{3,6})(?=\D\d{2,})/i is not the what challenge is looking for. It may passes the tests, but as you mentioned this \D looks redundant here, and of course it is.

Seems you just used one available default/sample pattern with some small changes that with luck it passed the tests.

This pattern you asked is wrong, check the thread link I shared the link it contains some detailed info about correct and expected pattern.


#5

no one mentioned the challenge. why are you?


#6

I’m sensing English isn’t your first language, you can use your native language.

(I’ll just use Google translate)