Restrict Possible Usernames / G

Restrict Possible Usernames / G
0.0 0

#1

Tell us what’s happening:
Hello, i did this challenge but i really don’t get why the g flag is not correct here ? Can someone explain it to me ? thanks

Your code so far


let username = "JackOfAllTrades";
let userCheck = /^[a-z]{2,}\d*$/gi; // Change this line
let result = userCheck.test(username);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0.

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


#2

I’m no wizard here but it seems necessary because you only want one string and you are specifying the beginning and end.

Why does it cause it to fail? Beats me. When I type those same things into a regex tester with your regex, they pass. But for whatever reason it doesn’t work. Maybe someone smarter than me can figure it out. But I agree that g is probably redundant here.


#3

numbers at the end are not neccessary
simply type /^[a-zA-z]{2}/


#4

Is this the exact code that you passed with? Because this is what I get when I run it.

Your regex should match JACK
Your regex should match RegexGuru

So the global flag isn’t why this particular regex fails