I’m doing the freeCodeCamp curriculum and I got stuck at the regex part, at task 22: Restrict Possible Usernames.
freeCodeCamp is saying that the regex /[a-z][a-z]+\d*/gi
doesn’t match for “JACK”, “Jo”, “Oceans11”, “RegexGuru” or “AB1”, and I don’t see why it shouldn’t match (also, regexr.com says it does match)
Am I being dumb, or is the website broken?
Additionally, the task also asks that the regex matches for “Z97”, and I don’t see how I would accomplish this: the word needs to have two characters or more, it can’t start with a number, it can only have numbers at the end, if it is only 2 characters it can’t have numbers
Any Help would be highly appreciated! thank you
You do not need the
g flag. That is only necessary when you are trying to match multiple instances of the same regex pattern. In this challenge, that is not necessary. The reason you are failing 2 of the last 3 tests is because of your second
[a-z]. Having that in there only matches if the first two are letters and that is not part of the requirement. Your regex matches
BadUs3rnam3 when it should not, because it allows numbers in the middle of the string and the requirement is numbers should only be at the end.
yes, I looked at some other topics on this forum that also asked for help on the same task. They linked to a post explaining the deal with the global flag. then after some thinking I managed to do it with
a little frustrating because the regex section hasn’t gone over using parentheses yet, but I guess it’s fine