How many times is phrase found in string?
by CJ Ramki
HTML
<p>Visit WHAK.com for WHAKy things!</p>
<p id="out"></p>
JavaScript
function howMany(str, term){
return str.match(new RegExp(term, 'g')).length;
};
var text='Visit WHAK.com for WHAKy things!';
var phrase='HAK';
out.innerHTML = phrase+' is found in\n'+text+'\n'+howMany(text,phrase)+' times.';