Why doesn't c57bT3 match?

I got the right answer, but I don’t understand why c57bT3 isn’t a match

The answer:


let username = "JackOfAllTrades";
let userCheck = /^([a-z]{1,}\d{2,}|[a-z]{2,})[0-9]*$/i; // Change this line
let result = userCheck.test(username);

To me the alternative on the left side of the “|” should be triggered because c57bT3 has 1 letter, and at least 2 numbers at the start. There are also 0-infinite digits at the end of the code (I’m referencing the [0-9]*$). What is it about this regex and string that makes them not match?

Thank you for any help!

Your browser information:

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

Challenge: Restrict Possible Usernames

Link to the challenge:

Notice that you are matching string from the start to the end. c57 is being matched by the [a-z]{1,}\d{2,} but after that, to the end there can be only 0 or more digits. The rest of string doesn’t match the [0-9]*$ making the whole string not matching.

1 Like

I get it, that makes sense! I falsely believed the $ made the regex match from end to start, I think that’s where my confusion was.

Thank you!