Could someone explain this?

Tell us what’s happening:
Describe your issue in detail here.

Wouldn’t the \w{6} restrict all the passwords being entered to have exactly 6 characters. I understand that’s not what is happening but I believe when only one number is entered in the curly braces with no coma that would mean the that the characters should be 6 in number. No more or less than 6. This is confusing me and would be great if someone could clear this out for me.

Your code so far

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36

Challenge: Positive and Negative Lookahead

Link to the challenge:

when tried this \w{6} it’s doing what its supposed to
perhaps you should look more closely into those ‘quantifiers’, for more clarification on quantifiers and regex in general please have a look at this , happy coding :slight_smile:

1 Like

Thank you for your reply. Do you think \w{6} means that the string should have a minimum of 6 characters or that it should have exactly 6 characters. I’m sorry if this question seems too basic. I’m a beginner who is trying to learn and it seems a bit confusing right now. Hope to hear from you.

1 Like

\w{6} matches 6 characters, any string that contains at least 6 consecutive characters. To make a regex match exactly what want, you should contain it in the symbols to which mean start with and end at - ^...$

1 Like

it means exactly, perhaps consider reading through this article as well :slight_smile:

we’re all here to learn from each other, so get psyched and happy learning :slight_smile:

1 Like

Thank you very much. That clears up what I was confused about.

Thank you for your reply.

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