Overlapping Regular Expression Matches With findall()

Fredrik Lundh fredrik at pythonware.com
Thu Dec 15 19:26:58 CET 2005


"Mystilleef" wrote:

> Is there a simple flag to set to allow overlapping matches
> for the findall() regular expression method? In other words,
> if a string contains five occurrences of the string pattern
> "cat", calling findall on the string returns a list
> containing five "cat" strings. Is it possible for findall()
> to just return one "cat" string?

your definition of "overlapping" seems to be a bit odd, but assuming
your description is correct, the answer is no.

on the other hand, if you only want one hit, why not use "search"
instead of "findall" ?

</F>






More information about the Python-list mailing list