Problem understanding "Regular Expressions: Restrict Possible Usernames" challenge

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames

In the above challange, the answer should be

let userCheck = /^[a-z]{2,}\d*$/i;
but I wrote

let userCheck = /\w[\D]/gi; // Change this line
it shows that my answer is correct. why does it happen?

My guess is that it is a bug in the fcc testing. If you go to


and put in your regex and then test “JACK”, “J”, “Oceans11”, etc. you will see your regex is not a full match for any of the tests. However, /^[a-z]{2,}\d*$/i is a full match.

1 Like

The issue is that you are not using anchors (^, $), and you are using the g flag with the test method, which you totally shouldn’t use if you haven’t read documentation about it

1 Like

thank you very much.

can you give me a link where I can clear all my confusion about Regex?

I don’t know, it depends on what you are confused about

Maybe take a look at this:
https://codeburst.io/javascript-learn-regular-expressions-for-beginners-bb6107015d91

1 Like