Regex exercise mistake?

The following is given as an example for this challenge:


let A4 = "haaaah";
let A3 = "haaah";
let A100 = "h" + "a".repeat(100) + "h";
let multipleHA = /a{3}h/;
multipleHA.test(A4); // Returns false
multipleHA.test(A3); // Returns true
multipleHA.test(A100); // Returns false

From my understanding would these not all be true as they do indeed contain “aaah” should the regex perhaps be

let multipleHA = /ha{3}h/;

?

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/specify-exact-number-of-matches

Good question. Because the regular expression does not include the start-of-line character (^), the a does not have to be the first letter in the string. A regular expression looks for the pattern anywhere in a string. It would also return true for '"Baaah!" said the little sheep'.

Their example answers are wrong. They use /a{3}h/ instead of /ha{3}h/ as indicated here:

For example, to match only the word "hah" with the letter a 3 times, your regex would be /ha{3}h/.

so they would all be true with let multipleHA = /a{3}h/;. So the regex should be as you indicate, correct.