Tell us what’s happening:
I have been stuck in this problem for quite some time. Could someone help me please? Thanks in advance!
Your code so far
let username = “JackOfAllTrades”;
let userCheck = /[^\d*]\w/i; // Change this line
let result = userCheck.test(username);
let username = "JackOfAllTrades";
let userCheck = /^\w$\d*/i; // Change this line
let result = userCheck.test(username);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36
.
Challenge: Restrict Possible Usernames
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames
Hello!
There are some problems with your RegEx.
-
\w
will match any word character: a-zA-Z0-9_
, but the challenge asks for alpha numeric characters: a-zA-Z0-9
.
- The
$
is used to delimit the end of a string, hence it should be a the end. In your RegEx, you’re saying match a string that has a single character. The \d*
is not taken into account in your RegEx (\w
would always match first).
- You’re allowing many tests cases to pass. Check the console:
// running tests
Your regex should match JACK
Your regex should not match J
Your regex should match Jo
Your regex should match Oceans11
Your regex should match RegexGuru
Your regex should not match 9
Your regex should match Z97
// tests completed
Check this online regex tester and see if it helps you understand what you’re doing wrong
,
Regards!
PD: $
for your specific RegEx must go at the end, but it can be inside a group.
I ended up looking at the solved equation
but now I understand what I was not doing right. And am able to solve the problem now with full understanding of what I am typing.
-Thankyou for your time