Counting sub-strings : <p>If you want to count the number of occurrences of one string inside another, which approach is better in terms of simplicity and/or performance? - </p>

<ul>
<li>using <code>indexOf</code> in a <code>for</code>/<code>while</code> loop</li>
<li>using a regular expression</li>
</ul>

<p>And if it is the latter, then what is the best way to do it?</p>
