Can I add a variable to Regular Expression?

Viewed 18

I am trying to include a simple regular expression " / /g" in my function but it doesn't work. The code I created below is to check how many "s" letter appears in the string "Christmasss". Thank you for sharing your answer in advance!

const charCount = (a, b) => console.log(a.match(/b/g.length));
charCount('Christmasss', 's');
0 Answers
Related