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?
[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 regexr.com or regexpal.com . These sites can tell you the meaning of each part of your regular expression, and you can test it interactively.