Restrict Possible Usernames doesnt function properly

Tell us what’s happening:
Problem: I don’t think this should pass the test, should it? Couldn’t find a report bug feature so posted this here.

Even more weird is: adding console.log(userCheck.test("a2da")) makes the first check fail but the others not.
The string “a2da” passes the test I passed this with. Found out a proper solution myself though.
Your code so far


let username = "JackOfAllTrades";
let userCheck = /\w\w/g; // Change this line
let result = userCheck.test(username);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames (cant post links yet says the forum)

  1. The only numbers in the username have to be at the end. There can be zero or more of them at the end.
  2. Username letters can be lowercase and uppercase.
  3. Usernames have to be at least two characters long. A two-letter username can only use alphabet letter characters.

Your regex is:

/
  \w # any single word character (A-Z, a-z, 0-9, or _)
  \w # any single word character (A-Z, a-z, 0-9, or _)
/g   # match globally, so in this case, anywhere in the string

So you are saying “this check should return true if the string has two word characters one after the other anywhere in the string”

“JackOfAllTrades” does, so no problem
“a2da” also tests as true, you fail the challenge because of condition 1 (there can be numbers, but they have to be at the end).

Your regex will test true for “01”, or “__” which fails condition 3. It will also test true for “1JackOfAllTrades” or “123456a”, these fail condition 1.

The regex should try to match:

Start of string, followed by
Two or more characters that are A-Z or a-z, followed by
zero or more numbers, followed by
End of string
(not global)

Hey, thanks for the answer.

I’m saying my regex (/\w\w/g) passes the test whereas it shouldn’t. I was able to figure out a proper way to do it, thanks for further explaining it though!

https://imgur.com/XuIt4K8