Regexp exercice: "Restrict Possible Usernames"

Regexp exercice: "Restrict Possible Usernames"
0.0 0

#1

Tell us what’s happening:

I think I’m getting better and better with regular expressions every day. But I’m stil missing something in this exercice: this condition -> Usernames have to be at least two characters long. A two-letter username can only use alphabet letter characters.

There is no reglar expression syntax that allows to specific nth time a character has to repeat if I recall…Or am I wrong?

Your code so far


let username = "JackOfAllTrades";
let userCheck = /[a-zA-Z]\d*$/; // Change this line
let result = userCheck.test(username);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0.

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


#2

Hello!

I went through these challenges myself not so long ago and got stuck on the same problem.
You can use “X{n}” to check if X matches n times.

You can see a bit of documentation on it here http://www.java2s.com/Tutorial/Java/0130__Regular-Expressions/Matchaparticularcharacteraspecifiednumberoftimes.htm

Good luck!


#3

Yes it worked with X{n}! Thanks! But this new syntax comes later in the exercices, and is not yet intrioduced in this exercice, and that is why I wasn’t able to find the solution.

It was introduced here: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/specify-upper-and-lower-number-of-matches


#4

I don’t want to create a new thread for this other problem but is there a bug in FCC with this exercice?

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/specify-upper-and-lower-number-of-matches

The error message is “Your regex should not match “Ohhhhhhh no””

But the {3,6} is 3 to 6 times inclusive, right?
My code

let ohStr = "Ohhh no";
let ohRegex = /h{3,6}/; // Change this line
let result = ohRegex.test(ohStr);

#5

Your latest code above will return true if there are 3, 4, 5, of 6 consecutive “h” found in ohStr.


#6

I think that the test case you most likely weren’t passing is this:

Your regex should not match J

In order words, the Username can’t be a single character string. Doing the below should get you through.

let username = "JackOfAllTrades";
let userCheck = /\w[a-zA-Z]\d*$/; // Change this line
let result = userCheck.test(username);

I hope this helps! :slight_smile: