I am trying to get the index of the exact search string, I have built a function that returns the index the match strings where I need to get the index only with the exact match
here is my function
getIndicesOf = (searchStr, str) => {
var searchStrLen = searchStr.length;
if (searchStrLen === 0) {
return [];
}
var startIndex = 0,
index,
indices = [];
while ((index = str.indexOf(searchStr, startIndex)) > -1) {
indices.push(index);
startIndex = index + searchStrLen;
}
console.log("detercting " , indices );
return indices;
};
console.log(getIndicesOf("go" , "go, I am going ")); // [0, 9]
here I go the index of go and going , How can get the index only of the exact match string?
stris"go, I am going "which contains no semicolons? Did you want to forbid commas after the "o"? Or did you want to forbid more words after the "o"? (with those conditions, nothing will be matched given your input)