I tried to follow this answer but it doesn't work when there are multiple occurrences of the same word.
I want to count the occurrence of both site and site web in the string "site web site".
I tried with the following code :
var regex = /(?:\b)((?=(site))(?=(site web)))(?:\b)/;
var string = 'site web site';
var match = string.match( regex ).filter(Boolean);
console.log(match)This code returns ["site", "site web"] but I want it to return ["site", "site", "site web"] since site appears two times in the string.
Note : In my case, I have hundreds of words to match.
More, if the input is site webS site, the expected output is ["site", "site"]. The input is supposed to be a complete text with punctuations to take into account (.,?!/;...).
 
    