Find all occurrences of a substring

 

1. re 사용

import re

[m.start() for m in re.finditer('test', 'test test test test')]
# [0, 5, 10, 15]

https://stackoverflow.com/a/4664889

2. Standard library 사용

def findAll(s, idx):
  e = s[0]
  i = s.find(e)
  while i is not -1:
    yield i
    i = s.find(e, i + 1)

https://stackoverflow.com/a/34445090