I'm new to regular expressions and would like to understand how findall() and lookahead can be used to find all occurrences of a given pattern within a string. I am having problems with alternating characters. Here is an example of what I want:
s = 'ababa4abaab'
p = 'aba'
print([ s[i:i+len(p)] for i in range(len(s)) if s[i:i+len(p)]==p])
['aba', 'aba', 'aba']
Here is my attempt with findall():
import re
re.findall('aba', 'ababa4abaab')
['aba', 'aba']
It only returns 2 matches but I want all three. I read this tutorial but did not quite understand. I tried
re.findall('(?=aba)', 'ababa4abaab')
['', '', '']
Can someone please tell me how to use this lookahead concept in this case and provide a brief explanation of how it works?