 # Regular Expressions: Specify Upper and Lower Number of Matches vs Regular Expressions: Specify Only the Lower Number of Matches

Regular Expressions: Specify Upper and Lower Number of Matches vs Regular Expressions: Specify Only the Lower Number of Matches
0

#1

Hello! I don’t understand why in this challenge
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/specify-only-the-lower-number-of-matches we do
let haStr = “Hazzzzah”;
let haRegex = /z{4,}/; // Change this line
let result = haRegex.test(haStr);
but here(https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/specify-upper-and-lower-number-of-matches/) we do
let ohStr = “Ohhh no”;
let ohRegex = /Oh{3,6}\sno/; // Change this line
let result = ohRegex.test(ohStr);
In hazzzah we need only z but in oh no we need to write also oh no why this? why not only h ? can someone explain it?

#2

although this passes the first challenge you linked to, it is actually incorrect. The test cases are not showing you this but if the test cases had a test for not matching ‘zzzz’ this regex would have failed.

So the reason is simple, the test cases are different, and not necessarily fulfilling the original intention of the problem.

#3

Thank you for the reply. So how should I write it correctly?

#4

@hbar1st why is it incorrect.
question:
In hazzzah we need only z but in oh no we need to write also oh no why this? why not only h ? can someone explain it?
it is for the purpose of specifying the word where to find the match
try running this code:
let testOne = “Ohhh no match”;
let test = /Oh{3,6}\sno/; // Change this line
let answerOfTest = testOne.match(test);