overlapping regex
Kenneth McDonald
kenneth.m.mcdonald at sbcglobal.net
Wed Jun 16 01:18:53 EDT 2004
In article <mailman.21.1087337004.21521.python-list at python.org>, km wrote:
> Hi all,
>
> python re module deals with only nonoverlapping matches. how to go for if i want to find out overlapping matches and their span ?
> regards,
> KM
>
The easiest way would be to, after you've found a match (using something
like the search method of comipiled re's), repeat the search starting
one character further along that the start of the previously found
match. This strategy may require some adjustment depending on the
exact patterns you're using, since you may find you don't want
_all_ overlapping patterns, but it should work and I can't think of
a better way of doing it.
Cheers,
Ken
More information about the Python-list
mailing list