Find how many times a search phrase is found in a string andrey понедельник, 6 октября 2014 г. No Comment

Here is the function to tell how many times a search phrase is found in a string.

Note: It's case sensitive.

function howMany(str, term){
return str.match(new RegExp(term, 'g')).length;
};

var text='Visit WHAK.com for WHAKy things!';
var phrase='HAK';
alert(phrase+' is found in\n'+text+'\n'+howMany(text,phrase)+' times.')

Thanks Christian White
Here is the function to tell how many times a search phrase is found in a string.

Note: It's case sensitive.

function howMany(str, term){
return str.match(new RegExp(term, 'g')).length;
};

var text='Visit WHAK.com for WHAKy things!';
var phrase='HAK';
alert(phrase+' is found in\n'+text+'\n'+howMany(text,phrase)+' times.')

Thanks Christian White
by Jillur Rahman

Jillur Rahman is a Web designers. He enjoys to make blogger templates. He always try to make modern and 3D looking Templates. You can by his templates from Themeforest.

Follow him @ Twitter | Facebook | Google Plus

No Comment