How do I get all possible overlapping matches in a string in Python with multiple starting and ending points.
I\'ve tried using regex module, instead of default re m
Regex are not the proper tool here, I would recommend:
code:
def find(str, ch):
for i, ltr in enumerate(str):
if ltr == ch:
yield i
s = "axaybzb"
startChar = 'a'
endChar = 'b'
startCharList = list(find(s,startChar))
endCharList = list(find(s,endChar))
output = []
for u in startCharList:
for v in endCharList:
if u <= v:
output.append(s[u:v+1])
print(output)
output:
$ python substring.py
['axayb', 'axaybzb', 'ayb', 'aybzb']