Stupid Regex Question

Jonas Galvez jonas at jonasgalvez.com
Wed Apr 21 12:59:24 EDT 2004


> [Fredrik Lundh]
> print re.findall("<tag>(.*?)</tag>", str)

WOW! Thanks a bunch (again).

Hehe, I had already written the following:

def getIndices(str, base):
    indices = []
    offset = 0
    while True:
        i = base.find(str, offset)
        if i == -1: break
        indices.append(i)
        offset = i+1
    return indices

def getContent(a, b, str):
    content = []
    startIndices = getIndices(a, str)
    endIndices = getIndices(b, str)
    startSlice = len(a)
    def add(s, e):
        content.append(str[s+startSlice:e])
    map(add, startIndices, endIndices)
    return content

Ouch.





=-
Jonas Galvez
jonasgalvez.com/blog
macromedia.com/go/team








More information about the Python-list mailing list