Lookahead query

I would like to know if the \w+ or \w* part is needed in the challenge. Or the \D* part in the example.
So why is it? It is not possible to ignore it or why is it so important?


let sampleWord = "astronaut";
let pwRegex = /(?=\w{6,})(?=\w+\d{2})/; // Cambia esta línea
let result = pwRegex.test(sampleWord);


You wrote the solution, why did you think that the \w+ was necessary? What happens if you remove it?

if I remove it, it doesn’t work :confused:

both lookahead start looking at the same position

Do you understand what the quantifiers do?

I searched on this Lookahead topic and I think I understand it a lot (obviously not perfectly), but I can’t figure out why it is necessary in this case.

because both lookaheads start looking at the same position, so putting in \w* you are saying that there can be any number of characters before the two consecutive digits

ahh well so I always have to specify what comes before what I want in a next Lookahead pattern?

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