const sourceStr = 'I learned to play the Ukulele in Lebanon.'; const searchStr = 'le'; const indexes = [...sourceStr.matchAll(new RegExp(searchStr, 'gi'))].map(a => a.index); console.log(indexes); // [2, 25, 27, 33]