[javascript] Count number of matches of a regex in Javascript