Count the number of occurence of a case sensitive word in a paragraph in jquery
<p>I want to count the number of occurrence of a specific words in a paragraph.</p>

<p>I am writing my code for key down event. I may have few hundreds words initially that may increase later on.</p>

<p>SO when the user is typing i will match the words in a paragraph and then get the number of occurrence. I also need to make sure that the match will be case sensitive.</p>

<p>Right now i am using this code:</p>

<pre><code>$('.msg').val().split("AP").length - 1
</code></pre>

<p>Where AP is the keyword to match.</p>

<p>But i am not very happy with this.</p>

<p><strong>Actually i have a list of few hundred keywords, how can i implement it efficiently.</strong></p>

<p>Please note the words to match have spaces on both side i.e they are boundary words</p>

<p>Any help is appreciated</p>
