string.count issue (i'm stupid?)

Alexander Schmolck a.schmolck at gmail.com
Mon May 22 07:25:47 EDT 2006


"Dirk Hagemann" <DirkHagemann at gmail.com> writes:

> I think I can tell you WHY this happens, but I don't know a work-around
> at the moment.

len(re.findall('_(?=a_)', '_a_a_a_a_'))

# untested
def countWithOverlaps(s, pat):
    return len(re.findall("%s(?=%s)" % (re.escape(pat[0]), re.escape(pat[1:])),s))

'as



More information about the Python-list mailing list