doing hundreds of re.subs efficiently on large strings

Anders J. Munch andersjm at
Thu Mar 27 14:42:02 CET 2003

"Alex Martelli" <aleax at> wrote:
> Yeah, but having to keep track of "one after the latest .end" in
> the loop to accumulate the fragments is fussy and may be a bit
> error-prone.  

When you know a better way.  That replacements could be functions had
escaped my attention; your solution is clearly better.  No
measurements needed to realise that.

And both solutions may or may not be better that the OPs original
one-sub-at-a-time approach.  I'll leave it to the OP to find that out.
After all, the OP can do the testing with the right regexps on the
right data.  Synthetic benchmarks give synthetic results.

- Anders

More information about the Python-list mailing list