title: Python regular expression findall using Lookahead
body: <p>I'm new to regular expressions and would like to understand how <strong>findall()</strong> and <strong>lookahead</strong> 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:</p>
  
  <pre><code>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']
  </code></pre>
  
  <p>Here is my attempt with findall():</p>
  
  <pre><code>import re
  re.findall('aba', 'ababa4abaab')
  ['aba', 'aba']
  </code></pre>
  
  <p>It only returns 2 matches but I want all three. I read <a href="https://docs.python.org/3/howto/regex.html#regex-howto" rel="nofollow noreferrer">this</a> tutorial but did not quite understand. I tried</p>
  
  <pre><code>re.findall('(?=aba)', 'ababa4abaab')
  ['', '', '']
  </code></pre>
  
  <p>Can someone please tell me how to use this lookahead concept in this case and provide a brief explanation of how it works?</p>