Find all occurrences of a substring in Python
- by cru3l
Python has string.find() and string.rfind() to get the index of a substring in string.
I wonder, maybe there is something like string.find_all() which can return all founded indexes (not only first from beginning or first from end)?
For example:
string = "test test test test"
print string.find('test') # 0
print string.rfind('test') # 15
#that's the goal
print string.find_all('test') # [0,5,10,15]