let username = "JackOfAllTrades";
let userCheck = /\w[a-z]/gi; // Change this line
let result = userCheck.test(username);
/\w[a-z]/gi; Looks like the \w automatically says it cannot start with a number because its the same as [A-Za-z0-9_] but it can include uppercase and lowercase character plus numbers 0-9.
Then the [a-z] says if the username is less than 2 characters it can only contain alphabet letter characters.
Am I understanding and interpreting this correctly?
Thanks for clarifying, I juts saw I was also able to pass the test without the g flag and only the i which ignores the letter case while matching /\w[a-z]/i. I just want to know if this \w shorthand character class is like responsible for this point in the test.Does the shorthand character put alphabet letters first and then numbers.
The only numbers in the username have to be at the end. There can be zero or more of them at the end.
Good question. You don’t need g flag because you are testing single words and not multiple words in a string. i is not necessary because /w is case-insensitive.
Does the shorthand character put alphabet letters first and then numbers? No. It can be either way.
I will refer you to my favorite website to test regexs so that you can see on your own https://regexr.com/
@GitCharly I’ve gone through at least 5 different posts looking a simplistic explanation as to how someone got their answer. Yours is the first to do just that. I wasn’t looking for the answer itself, just a better understanding of why people chose what they chose. So far, yours is the best I’ve seen. As someone who learns best by understanding the “why,” I really do appreciate you taking the time to explain how you came about your solution. Thank you.