Specify Only the Lower Number of -Matches

Specify Only the Lower Number of -Matches
0

#1

Tell us what’s happening:
What can I should do more?

Your code so far


let haStr = "Hazzzzah";
let haRegex = /Haz{4,}ah/g; // Change this line
let result = haRegex.test(haStr);

Your browser information:

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

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


#2

You don’t need g flag at the end.


#3

Thank for helping this is right.


#4

Can I ask though - what is it that the g flag does that makes having it at the end of that expression such a bad thing? (I had the same code til I saw this post.)


#5

There is a great explanation on Stack Overflow for this very question.


#6

Thanks - read through that and still pretty clueless (a depressing pattern that’s developed between me and stackoverflow). lastIndex hasn’t been mentioned thus far in the FCC Regex tutorials… What is it, and why does it matter?

From what I understand, adding g at the end means that the test/match/whatever will return all the instances of the regex it finds. so if there’s one match, it will return that. If there are 1500 matches, it returns all 1500. This doesn’t seem like the kind of thing that should mess me up in this scenario?


#7

Strange thing is, /z{4,}/ seems to work for me, But I dont think it should pass though…