trying to find repeated substrings with regular expression

johnzenger at johnzenger at
Mon Mar 13 23:33:11 CET 2006

Robert Dodier wrote:

> I've decided it's easier for me just to search for FOO, and then
> break up the string based on the locations of FOO.
> But I'd like to better understand regular expressions.

Those who cannot learn regular expressions are doomed to repeat string
searches.  Which is not such a bad thing.

txt = "blah FOO blah1a blah1b FOO blah2 FOO blah3a blah3b blah3b"

def fa(s, pat):
    retlist = []
        while True:
            i = s.rindex(pat)
            s = s[:i]
        return retlist

print fa(txt, "FOO")

More information about the Python-list mailing list