function countNonOverlappingOccurrences(str: string, substr: string) {
return (str.length - str.replace(new RegExp(substr, "gi"), "").length) / substr.length;
}
const s: string = "phptypescript php c++ python php phphp";
console.log(countNonOverlappingOccurrences(s, "php"));
/*
run:
4
*/