A little problem with > JS and Data structures: Regex: Match Numbers and Letters of the Alphabet

Tell us what’s happening:

here’s what appeared (and no matter how much I try again it still appears) in the console.

// running tests Your regex
myRegex should match 17 items.
// tests completed

This exercide is quite easy. It’s not complicated. I know my code is correct, since I already took a look at the solution, but I can not figure out what the problem here is. Maybe it is a bug.

Your code so far

let quoteSample = "Blueberry 3.141592653s are delicious.";
let myRegex = /h-s2-6/gi; // Change this line
let result = quoteSample.match(myRegex); // Change this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36 Edg/89.0.774.45.

Challenge: Match Numbers and Letters of the Alphabet

Link to the challenge:

If your solution doesn’t work, your code isn’t correct :wink:

But in this case the mistake is rather simple.
If you log your result to the console, it returns ‘null’.
So there are no matches with your regex.
The reason for this is, that your regex matches ‘h-s2-6’ literally.

let myRegex = /h-s2-6/gi
let quote = 'i3'
let secondQuote = 'h-s2-6'
console.log(quote.match(myRegex)) // This returns null
console.log(secondQuote.match(myRegex)) // This returns 'h-s2-6'

Just compare your regex to the example given in the challenge :wink:


You need to put [ ] to get the code working.

let myRegex = /[h-s2-6]/gi;

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like

My bad! Sorry :grimacing: