Problem with the Hint 2 (Positive and Negative Lookahead)

Hello!

The problem is related to the Hint 2 (freeCodeCamp Challenge Guide: Positive and Negative Lookahead) of the challenge " Positive and Negative Lookahead" (https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/regular-expressions/positive-and-negative-lookahead)

The Hint 2 finishes with “Remember to specify the exact amount of numbers you want to appear at the end of the string.”

But the checklist in the challenge says that “Your regex should match the string astr1on11aut”.

I’m novice, so I might be wrong, but I think that it should be like “Remember to specify the exact amount of numbers you want to appear consecutively on the string.”

Anyway, if I’m wrong, I’m sorry and, if it’s possible, explain me why it is right.

Kind regards!
Marcos.

3 Likes

Hi Marcos,

Remember this paragraph from the first lesson or challenge in the Regular Expressions course (https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/regular-expressions/using-the-test-method)?

I quote it below:

" If you want to find the word the in the string The dog chased the cat , you could use the following regular expression: /the/ . Notice that quote marks are not required within the regular expression. "

With that understanding, I think the statement you referenced from Hint 2 is talking about the string that you put in myRegex.

So this is what I think it meant to communicate : Remember to specify the exact amount of numbers you want to appear at the end of the regex string.

I think thus that your concern is legitimate.

Best regards.

4 Likes

Thanks!
That makes more sense now!
Thank you so much!! =D

2 Likes

Welcome Marcos. I’m glad.

1 Like

(?=\w*\d{2,}) hello :wave:
dont understand why do we need \w at first wright
and why this combination works, but not togeather

//(?=\d{2})/ // filter for at list 2 numbers

//(?=\w{6})/   // filter for more then 6 symbols
2 Likes

I am novice too and maybe could be wrong but as far as I understand when it specifes that you have to find exact matches, like in this case, 2 consecutive digits, it means that you have exclude everything else and just look for two consecutive digits. Correct me someone if I’m wrong, please.

the two lookaheads look from same position, if you don’t write \w* then the second lookahead is imposing that the numbers have to be at the start of the 6 characters matched by the other lookahead

8 Likes

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