re.findall

Matthias Huening mhuening at zedat.fu-berlin.de
Fri Jul 16 11:24:29 CEST 2004


hwlgw at hotmail.com (Will Stuyvesant) wrote in 
news:cb035744.0407160003.630701ee at posting.google.com:

> A question about the findall function in the re module, and I also
> would be happy with pointers to online documentation with which I 
> could have found a solution myself (if it even exists!).
> 

The problem is that the strings you want to find are overlapping.
This should get you started:

import re

s = "i or j or k or grr"
pat = re.compile(r'\w+ or \w+')

startposition = 0
while 1:
	res = pat.search(s, startposition)
	if res == None:
	    break
	startposition = res.start() + 1
	print res.group()


Matthias



More information about the Python-list mailing list