Specify Upper and Lower Number of Matches-gt

Tell us what’s happening:
Even if no. of 'a’s is more than 5 still the statement will evaluate to be true. Not able to figure out what is the significance of mentioning lower and upper limit in curly bracket? Thanks in advance.

Your code so far


let A4 = "aaaah";
let A2 = "aah";
let multipleA = /a{3,5}h/;
multipleA.test(A4); // Returns true
multipleA.test(A2); // Returns false

Your browser information:

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

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

you need to put some kind of delimitation, for example the anchor for start of the string /^a{3,5}h/
or with capital letters

let str = "Aaaaah"
let str2 = "Aaaaaaaaaah";
let re = /Aa{2,4}h/;
re.test(str); // true
re.test(str); // false

if you use /a{3,5}h/ it will check if there is aaah, aaaah or aaaaah inside the string - if there are other letters before or after, even if those are other as doesn’t matter

1 Like

Perfect got that, There needs to be a character before the character to be put in curly bracket for the higher limit to work. When you use ‘A’ before ‘a’ then in the above example if ‘a’ becomes more than 4 then condition becomes false.