Tell us what’s happening:
I have the code below and I understand why it does not match Z97, but I’ve not been able to figure out how to fix it. Any ideas would be appreciated.
Thanks!
Your code so far
let username = "JackOfAllTrades";
let userCheck = /^[A-Za-z]+[A-Za-z]+\d*$/; // Change this line
let result = userCheck.test(username);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36.
Yes, I’m aware that I need to plan for both situations but I haven’t figured out how to do that (other than just looking at the solution). Thanks for the link. I checked it out but I have no idea what it’s for or how to use it. I didn’t really see any explanation or instructions.
Hi @Sharad823, i always seem to struggle with anything other than the most basic regexp too. Ive did this exercise some time ago and when looking to solve it gain just now I had to referred to this cheat sheet (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet) to help me out. Hopefully not giving to much away by pointing you in the direction of the " | " for alternation and you need to look at capturing groups with ( ) and quantifiers using {}
On regexr you can enter all your test cases at once. While you fiddle with the code it highlights the matches. Just make sure you use the “m” flag. (flags are in the upper right corner)