Regex Advice for Username Exercise

Tell us what’s happening:
Describe your issue in detail here.

My problem is that my regex are matching cases where there is an integer embedded between characters. I am having difficulty understanding why this is the case, and how I can write a regex that can account for it.

I would also like advice in simplifying my regex. I currently have a “|” operator to include a specific edge case where we have a username with 1 character followed by two integers, and I suspect there might be a single regex to account for all of these situations.

Your code so far

let username = "JackOfAllTrades";
let userCheck = /[a-z][a-z][a-z|\d]*$|[a-z]\d\d/i; // Change this line
let result = userCheck.test(username);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36

Challenge: Restrict Possible Usernames

Link to the challenge:

i have played with the challenge a bit. It looks like the use of the condition operator “|” is inevitable.
What your regex lack is to tell what the name should not start with(or what it should start with) and to do that you should utilize “^”.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.