JavaScript - RegEx freeCodeCamp Test fail ?!

Hello everyone,
searched a bit on the forum but didnt’ find the same issue.

I am refering to this test

This is the code I made up:

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

This is the output of console.log(s)():

When running the test in freeCodeCamp editor the RegexGuru match doesnt result matched:
// running tests

Your regex should match RegexGuru

// tests completed

Is my RegEx wrong ?

That said, to me the [a-z][a-z]+ pattern seemed really bad so wanted to check the “Get a Hint” link. There the pattern used above is replaced with {2,} which is not explained in the previous lessons. Am I blind or that should be explained before giving it as a Solution ?


Your regex is fine, remove the g flag and it will pass. Not sure why though, probably just the tests being too strict.

I remember a class that teaches this regex {2, }, basically it means “match 2 or more”. You’ll learn it later. It would be nice if it was before the solution though :smiley:

It works as you said, hope it’s really something not working quite good under the hood in the freeCodeCamp editor, tried even on and it matchets.

P.S. I suggeast the {min,max} pattern should be put before but that just my 5cent