I am working on a problem from FreeCodeCamp that involves me developing a Regular Expression that meets these four requirements:
- Usernames can only use alpha-numeric characters.
- The only numbers in the username have to be at the end. There can be zero or more of them at the end. Username cannot start with the number.
- Username letters can be lowercase and uppercase.
- Usernames have to be at least two characters long. A two-character username can only use alphabet letters as characters.
What I have decided on is /[a-z]/ig, which covers all of the test cases except for the following three:
- Your regex should not match the string
BadUs3rnam3 - Your regex should match the string
Z97 - Your regex should not match the string
c57bT3
What confuses me is that if I add numbers (\d) into my Regex then some of my simpler requirements ("Regex should match JACK") are now incorrect.
I was thinking that I could do something like:
/[a-b+?]*\d/
or this
/[a-b^0-9$]/
But that throws off things.
Can someone lend me a hand and explain how this might work?