I searched over the title and found some solutions, but none of them worked for me. I want something like following:
checkRepeat('ccc','cc'); // should give output 2
checkRepeat('cccaacddcccc','cc'); // should give output 5
and so on. Please help me with this.
What I've tried:
function checkRepeat(string, search) {
if (!search.length) return 0;
var pattern = new RegExp('(' + search + ')', 'ig'),
match = string.match(pattern),
parts = string.split(pattern).slice().filter(function (i) {
return i.length;
});
console.log(match.length);
console.log(parts.length - 1);
}