I am trying to find the count of number of occurrences of a substring in a string using
function countOccurences(str,word){
var regex = new RegExp("\\b"+word+"\\b","gi");
console.log((str.match(regex)|| []).length);
}
let String=' test TEST TESTING Test I like testing <h3>TEST</h3> class="test id="test" ';
let asset="Test";
countOccurences(String,asset);
Here, the result I am getting is 6, which is ok as I want the exact match, but I want to exclude the test of class and id, so that the result I get is 4 and not 6.