Anyone help me with JS please?

I am a bit confuse about this code, the first and second matches return [“cat”] and [“bat”] but why the third match return null please help me!
Thank you.

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

Challenge: Match Letters of the Alphabet

Link to the challenge:

Hi,

It’s because of [a-e] . Inside a regex this means : match any letter that is a, b, c, d or e and m is not included.

Greets,
Karin

Thank you so much, now I understand.

You’re very welcome!
Karin

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