doing hundreds of re.subs efficiently on large strings
Anders J. Munch
andersjm at dancontrol.dk
Thu Mar 27 09:36:34 CET 2003
"nihilo" <exnihilo at NOmyrealCAPSbox.com> wrote:
> How do I use finditer to find the unmatched parts also (the stuff
> between the matches)? It looks to me like it just gives you access to
> the stuff that is matched, but maybe I'm missing something.
Look at start() and end().
>>> s = 'hi nihilo'
>>> for m in re.finditer('(n)|(o)', s):
... print m.start(), m.end()
>>> s[:3], s[3:4], s[4:8], s[8:9], s[9:]
('hi ', 'n', 'ihil', 'o', '')
More information about the Python-list