Regular Expressions - Restrict Possible Usernames

Regular Expressions - Restrict Possible Usernames
0

#1

I don’t have a problem with this chalenge but I assume that somebody is going to have, and because of that I just want to post some hint.

In this one you should use quantifiers. This isn’t covered before this task.
You can check how to use it here


How is d different from \ d?
#2

I was working on this challenge. i think the solution that FFC accepts is wrong. It accepts:
/[a-zA-z]/g
However, i think its a wrong answer because, based on the rules that was given, Oceans11 should not pass the test using that expression. But it did.

I also agree with what @Saymon85 has said. You need to know about quantifiers, which was not covered. anyways, the below solution would meet all the rules yet, FCC console says it doesn’t meet the “JACK” test case, but it meets the rest.

/[a-z]{2,}\d+$|[a-z]{2,}/ig

  1. List item
    the first part after the | ensures that letter sequence with two or more characters, having numbers at the end of the word, passes the test
  2. List item
    the second part before | ensures that any letter sequence with two or more characters can pass the test {2,}.

feel free to verify all test cases in regex101.com


#3

I have exactly the same problem and my code is virtually the same…

/[a-zA-Z]{2,}\d+$|[a-zA-Z]{2,}/g

I tried it on repl.it and it works just fine, so is the console bugged?


#4

couldn’t you just leave out the part after | and instead use a * in place of the +? so

/[a-zA-Z]{2,}\d*$/g


#5

It wont work on all the tests. check regex101.com , put in that expression and test it using the same test scenarios’. Think of the ! as an “or” statement


#6

@Saymon85 Thanks for the advice on this, I was initially struggling and based on the tutorials on FCC couldn’t work out how to test for length, the {X} and {X,} suggestions helped.

@chinonsoebere thank you too, as I logically have worked out a solution which I think is correct, yet I can’t get it to pass the FCC tests, however using the regex101.com link proved my code is actually correct!

So for now I will just have to skip this challenge, leaving it as incomplete!

Am I allowed to post the code i’ve used as my solution on here? So you could maybe verify I got it correct?


#7

No qualifiers needed

let userCheck = /^[a-z][a-z]+\d*$|[a-z]\d\d/i;

I think…


#8

You’re welcome, we are here because of that :smile:
Yes, you are allowed it is good way to get help.


#9
Spoiler

let userCheck =/\w.\d?/g


#10

I think this is a short way to do it. Anything wrong with that ?

let userCheck = /\w./g; // Change this line

cheers mchoeti