Restrict Possible Usernames. "Regex = /\D\w{2,}/g;" can`t be passed

Restrict Possible Usernames. "Regex = /\D\w{2,}/g;" can`t be passed
0.0 0

#1

Tell us what’s happening:

Hi, i can’t pass this task, i tested it with following values and “match” returned “true”. What did i do wrong ?

Your code so far


let username = "JackOfAllTrades";
let userCheck = /\D\w{2,}/g; // 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/67.0.3396.87 Safari/537.36.

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


#2

Remove the g flag.


#3

Thank you, it solved my problem. But i still don`t quite understand what is wrong with g flag?


#4

The tests are probably using a match() call to check your regex. The g flag is just unnecessary for the challenge, but it results in a different returned value when checked with match().