let catStr = "cat"; let batStr = "bat"; let matStr = "mat"; let bgRegex = /[a-e]at/; catStr.match(bgRegex); batStr.match(bgRegex); matStr.match(bgRegex);

"In order, the three match calls would return the values [“cat”], [“bat”], and null.


My question is, why does the last one returns null?

Let us look at the regular expression. The key part here is [a-e]. Do you know what it means?

Hi Bvanb, thank you for your time.

doesn’t [a-e] means every vowel except for u?
shouldn’t mAt be in?

[a-e] matches any letter from “a” to “e” (abcde). It is looking for a word that starts with one of those letters, followed by “at”.

When using regular expressions, it is helpful to use a site such as or . These sites can tell you the meaning of each part of your regular expression, and you can test it interactively.

1 Like

perfectly understandable! Thank you very much

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.