If you run into the case where only the first occurrence is returned from the match function then you’ll probably missing a “g” flag at the end of your regular expression.
var sampleText = 'This is how to find all matches in the text.';
var matchedResults = sampleText.match(/[a]/g);
That’s all you need.