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? -
- using
indexOf
in afor
/while
loop - using a regular expression
And if it is the latter, then what is the best way to do it?