So basically I wrote myself this function so as to be able to count the number of occurances of a Substring in a String:
String.prototype.numberOf = function
r = new Regexp(r.source, r.flags + (r.global ? "" : "g"));