fork download
  1. import re
  2.  
  3. def findall_overlapped(r, s):
  4. res = [] # Resulting list
  5. reg = r'^{}$'.format(r) # Regex must match full string
  6. for q in range(len(s)): # Iterate over all chars in a string
  7. for w in range(q,len(s)): # Iterate over the rest of the chars to the right
  8. cur = s[q:w+1] # Currently tested slice
  9. if re.match(reg, cur): # If there is a full slice match
  10. res.append(cur) # Append it to the resulting list
  11. return res
  12.  
  13. rex = r'\d+'
  14. print(findall_overlapped(rex, '01'))
Success #stdin #stdout 0.02s 9364KB
stdin
Standard input is empty
stdout
['0', '01', '1']