I need help understanding this Regex?

I need help understanding this Regex?


I’m in the JavaScript Lesson “Specify Upper and Lower Number of Matches” and I am kindof confused by the correct answer:

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

This is my understanding & confusion:
-The first segment “oh” checks the string starts with “oh” characters. Why doesn’t it work if you use “h” instead?

-The second segment “{3,6}” searches for “h” character 3 to 6 times. Or is it checking for the “oh” 3 to 6 times? Or checking for “h” 3 to 6 times following an “o”?

-The third segment searches for whitespace.

-The fourth segment searches for “no” characters. Why is this part necessary?

-The fifth segment “/i” ignores case.


Can you add a link to the exercise?



  1. Because it will only match its substring excluding o at the beginning.
  2. searches h character 3 to 6 times.
  3. Without it, it will only match "h"s.


Okay, thank you! I’m finding it difficult to follow the regex logic in these lessons, but hopefully with practice it will become clear.


Regex is like a receipe. try using a Regex Tester and cheat sheet to understand what you are looking at.



Excellent, thank you! I’ve been making notes as I go through the lessons but this looks much simpler to look at for fast reference.