How to find all the indexes of all the occurrences of a word in a string in Python?
import re sentence = 'this is a sentence this this' word = 'this' for match in re.finditer(word, sentence): print(match.start(), match.end())
Output
0 4 19 23 24 28