var str = "The foxy fox jumps before dancing the Foxtrot.";
// Make search case-insensitive by converting to lower:
var foxSplit = str.toLowerCase().split("fox");
var foxCount = foxSplit.length - 1;
alert( "Found " + foxCount + " matches for 'fox' in the string" );
Note: by using toLowerCase(), we ensure that the last instance (capitalized) will be counted! You can also pass escaped characters as argument, like "\n" for new lines or "\t" for tabs.
var str = "The foxy fox jumps before dancing the Foxtrot.";
// "g" option to count all; "i" option to make case-insensitive
var rgx = /\sfox\S+/gi;
alert( "Found " + str.match(rgx).length + " matches!" );
Tip: the match() method captures each matching string, and returns them as an array of strings.