Iâm not sure why your regex is failing the tests, but it might have something to do with the g flag. I tried a couple of different regexs that met the requirements without using the g flag, and they both passed the tests. (Basically use {1,} instead of combining + and g to match one or more)
Remove the g flag - the g flag is for incremental matching - it is not needed for this exercise - it causes test cases to fail because the same regex variable is used for every test case
This regex is a simpler equivalent of yours: /^[a-z]{2,}\d*$/i
However the exercise has issues - username â007â should be allowed since it has more than 2 characters and has numbers only at the end - either the test case should be corrected or the exercise statement should be updated to restrict usernames to start with a letter or possibly 2 letters
The general brace expression is {m,n} that matches between m and n occurrences of the preceding item - no n means match at least m occurrences - no m means match at most n occurrences - {2,} means match at least 2 occurrences - {,2} means match at most 2 occurrences - you know what {2} means
Hi Alimama,
even though your code passes the test, itâs not quite correct. Here are few usernames that shouldnât go through, but your RegEx doesnât restrict them:
1Jack (Since the only digits in the username have to be at the end)
Ja33ck (Digits should be at the end)
Ja (should pass)
etcâŚ
Your RegEx allows digits in the begging and in the middle, and makes the word at least 4 characters long.
^[a-z] guarantees that your username starts with letter; ^[a-z]{2,} guarantees that it starts with letters and is at least 2 characters long; \d* says it can have 0 or more digits. \d*$ guarantees that digits are only at the end. i - ignore case.