Can't pass the Restrict Possible Usernames test

Tell us what’s happening:
The regex works as it should, but when I run the tests it says that it doesn’t match “RegexGuru” username

Your code so far

let username = "RegexGuru";
let userCheck = /[a-zA-Z][a-zA-Z]\w+/gi; // Change this line
let result = userCheck.test(username);
console.log(username.match(userCheck));
console.log(result);

Output

RegexGuru
true

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36.

first remove the g tag, you don’t want to use it with the test method

then try again and see what it is that you need to actually fix

You can see the whole story with the test method and the g flag in the examples in this page:

1 Like

It worked after removing the g flag. thank you!

Just so you know, your solution pass the tests but doesn’t actually complete satisfy challenge conditions

Try with usernames like “2Fluffy” or “Mag1cMe” that should return false

I give you an hint: anchors


Other thing, if you use the i flag you don’t need to do [A-Za-z] because the i flag already makes it case insensitive

1 Like