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