What are lookaheads in regexes?

What are lookaheads in regexes?

they are non-capturing groups that look after the captured pattern (and actually capture it only if the lookahead is respected)

https://www.regular-expressions.info/lookaround.html

1 Like

Thanks for the response.

in Regular Expressions: Positive and Negative Lookahead https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/positive-and-negative-lookahead

I have this code:

let sampleWord = "astronaut";
let pwRegex = /(?=\w{5})(?=\d?=\d)/; // Change this line
let result = pwRegex.test(sampleWord);

Some help with this please, as it doesn’t pass the tests.

there is repeated code inside here, should they be two different lookaheads or the pattern you are checking is actually \d?=\d (as in, digit, question mark, equal sign, digit)?

I am not sure about that.