Regular Expressions: Restrict Possible Usernames solved when it shouldn't be solved

I used this code to solve this problem freehand in regex101’s test environment:

/[a-z]{2,}+\d*/gi

which works with no issue:

image

but the test say’s that it’s incorrect. I then replaced the one or more matcher (+) with a lazy match (?) to get this:

/[a-z]{2,}?\d*/gi

Which the test says is correct, but as far as I’m aware and according to regex101, this only matches the individual 2 character pieces of the usernames.

image

I then looked in my console which technically agrees with the grader that the + works (since they ARE matched and valid which I guess is neither here nor there)

But I get the same successful message from my console with the one or more (+) which is what I believe to be the better/ correct solution:

At https://regexr.com/ this throws an error, saying there is nothing to repeat. Which is true, since the quantifier + is preceded by {2,} which matches 2 or more of the preceding token. Meaning it is already repeating.

You will get the right result because regex doesn’t throw an error for this, as far as I know. So it just won’t match that quantifier. But it looks like FCC is validating it somehow.

This passes the test because now you’re telling the regex engine to match at least 2 or more of the preceding token, and since the test only requires that it be at least 2 characters long, the ? quantifier will only match two characters and then move on.

This is a bug on the test since it matches subsets of the correct answers. What you’re looking for is one character off from your original answer

/[a-z]{2,}\d*/gi
1 Like

2 off actually. It appears the g for some reason stopped JACK and RegexGuru from being matched. I don’t think this is actually the case, but this section seems buggy so I’m not worried about it. global isn’t really necessary here anyways.

/[a-z]{2,}\d*/i was my solution