Help needed - Specify Upper and Lower Number of Matches

Tell us what’s happening:

let ohStr = "Ohhh no";
// let ohRegex = /^[a-gi-zA-GI-z]?h{3,6}\s/; // Change this line
let ohRegex = /^\w?h{3,6}\s/; // Change this line
let result = ohRegex.test(ohStr);
console.log(result);

My regex :
let ohRegex = /^\w?h{3,6}\s/; // Change this line
or
let ohRegex = /^[a-gi-zA-GI-z]?h{3,6}\s/; // Change this line

because this “/h{3,6}/” fails all referenced criteria when “Run Test” is selected.

let result = ohRegex.test(ohStr);

Section Question:
Change the regex ohRegex to match the entire phrase Oh no only when it has 3 to 6 letter h’s.

If I run a “console.log(result)” on the below “ohStr”'s, these are the results:

let ohStr = "Ohh no"; // false
let ohStr = "Ohhh no"; // true
let ohStr = "Ohhhh no"; // true
let ohStr = "Ohhhhh no"; // true
let ohStr = "Ohhhhhh no"; // true
let ohStr = "Ohhhhhhh no"; // false

But the challenge requirements to pass is returning an “X” for below:

  • Your regex should match the string Ohhh no
  • Your regex should match the string Ohhhh no
  • Your regex should match the string Ohhhhh no
  • Your regex should match the string Ohhhhhh no

And a “Check Mark” for the below options:

  • Your regex should use curly brackets.
  • Your regex should not match the string Ohh no
  • Your regex should not match the string Ohhhhhhh no

I basically gave up on another section because nothing seemed to work after a day and numerous YouTube videos and I am doing the same for this one because I am not understanding what is not work here.

When the example was " aaaah" === /a{3,5}h/ returns true.

Am I doing something wrong or could this possibly be a bug?
Any assistance would be greatly appreciated. Cheers!

Your code so far


let ohStr = "Ohhh no";
let ohRegex = /^[a-gi-zA-GI-z]?h{3,6}\s/; // Change this line
let result = ohRegex.test(ohStr);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36

Challenge: Specify Upper and Lower Number of Matches

Link to the challenge:

1 Like

you make things more complicated than they should be.
How would you match the phrase “Oh no”?
Its very simple: /Oh no/
How would you match the letter “o” between 5 and 10 times? - /o{5,10}/
It would match “ooooo”, or “ooooooo”, but it wont match “oo”.
How would you mwatch “Ohhh no”, but not “Oh no”? I leave that up to you ^^

PS:
^[a-gi-zA-GI-z]? This matches quite bit of characters and suggests the phrase start with it and actually the ? sign makes it not mandatory to be present in the match. It doesnt match with the challenge criteria. /^\w?/ is also very similar, we are not looking for any or no character in the start of a phrase, we are looking for a very specific character.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.