JPython - Problems using "re"

Magnus L. Hetland mlh at vier.idi.ntnu.no
Wed Dec 8 10:14:38 EST 1999


Or... perhaps as a function :)

import re

def findall(pattern, text):
    p = re.compile(pattern)
    result = []
    pos = 0
    m = p.search(text,pos)
    while m:
        g = m.groups()
        if len(g) == 1:
            result.append(g[0])
        else:
            result.append(g)
        pos = m.end()
        m = p.search(text,pos)
    return result

I'm not sure if it duplicates re.findall exactly, but it seems to work
OK...

--

  Magnus          Echelon jamming noise:
  Lie             FBI CIA NSA Handgun Assault Bomb Drug Terrorism
  Hetland         Special Forces Delta Force AK47 Hillary Clinton 



More information about the Python-list mailing list