JPython - Problems using "re"
Magnus L. Hetland
mlh at vier.idi.ntnu.no
Wed Dec 8 09:57:26 EST 1999
sdm at dcs.ed.ac.uk (Stephen McColl) writes:
> hi there,
>
[...]
>
> But in JPython, (JPython 1.1 beta 4), "findall" isn't a method in the "re" module.
> Is there another way to produce the same result (scan a string and return a list of
> all matches)?
Use a while-loop...
import re
p = re.compile("(pattern)")
t = "this text contains the pattern several times (pattern pattern)"
pos = 0
result = []
m = p.search(t,pos)
while m:
g = m.groups()
if len(g) == 1:
result.append(g[0])
else:
result.append(g)
pos = m.end()
m = p.search(t,pos)
print result
> Thanks for any help in advance.
>
> stephen.
>
> --
> _________________________________________
> stephen mccoll sdm at dcs.ed.ac.uk
> 4th Year Computer Science, Edinburgh University
>
--
--
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