Restrict Possible Usernames

Restrict Possible Usernames
0

#1

Tell us what’s happening:
I’ve verified this regex expression using https://regexr.com/ already, but the exercise keeps telling me that I’m failing to include “JACK” and “RegexGuru.”

Is there something wrong with my regex or is the exercise buggy?

Your code so far


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

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames/


#2

Just worked through the challenge myself to see what was going on and you only need the case insensitive option at the end.

:slight_smile:


#3

Haha oh my goodness. Thank you!!


#4

So what’s wrong with the g flag?


#5

This is another solution directly following from instruction provided:
let username = “JackOfAllTrades”;
let userCheck = /[a-z][a-z]/gi||/[a-z][a-z]+\d*/i; // Change this line
let result = userCheck.test(username);


#6

Since the previous solution by me follows directly from instructions, you can better understand why we don’t need g flag by running it without this global flag . So, the inference is we need g flag only when the pattern is repeated in the given problem, or in words it is global in nature. Thus following runs equally well since the given pattern is for one time implementation only:
let username = “JackOfAllTrades”;
let userCheck = /[a-z][a-z]/i||/[a-z][a-z]+\d*/i; // Change this line
let result = userCheck.test(username);