Okay, so I found this: How to find all occurrences of a substring?
Which says, to get the indices overlapping occurances of substrings in a list, you can use:
[m.start() for m in re.finditer('(?=SUBSTRING)', 'STRING')]
Which works, but my problem is that both the string and the substring to look for are defined by variables. I don't know enough about regular expressions to know how to deal with it - I can get it to work with non-overlapping substrings, that's just:
[m.start() for m in re.finditer(p3, p1)]
Edit:
Because someone asked, I'll go ahead and specfify. p1 and p3 could be any string, but if they were, for example p3 = "tryt"
and p1 = "trytryt"
, the result should be [0, 3]
.