As far as I can tell, my regex code is the equivalent to the solution code (e.g. swaps [a-z] for \D) but it’s failing several tests.
I have no idea why this is happening.
I’ve commented out the solution I based my answer from. Can anyone help me out please?
Your code so far
let username = "c57bT3";
let userCheck = /^\D(\d\d)|(\D+\d*)$/; // Change this line
let result = userCheck.test(username);
let matcher = username.match(userCheck)
console.log(result)
console.log(matcher)
/* ^ - start of input
[a-z] - first character is a letter
[0-9][0-9]+ - ends with two or more numbers
| - or
[a-z]+ - has one or more letters next
\d* - and ends with zero or more numbers
$ - end of input
i - ignore case of input*/
Other solutions I have tried are:
let userCheck = /^\D(\D|\d\D)/
let userCheck = /^\D(?=\D{1})(?=\D+\w*$)/; // Change this line
let userCheck = /^\D(\D|\d\w+)/; // Change this line
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0
.
Challenge: Restrict Possible Usernames
Link to the challenge: