On Mon, Jan 11, 2010 at 12:34 PM, Steven D'Aprano <st...@remove-this-cybersource.com.au> wrote: <snip> > If you can avoid regexes in favour of ordinary string methods, do so. In > general, something like: > > source.replace(target, new) > > will potentially be much faster than: > > regex = re.compile(target) > regex.sub(new, source) > # equivalent to re.sub(target, new, source) > > (assuming of course that target is just a plain string with no regex > specialness). If you're just cracking a peanut, you probably don't need > the 30 lb sledgehammer of regular expressions.
Of course, but is the regex library really not smart enough to special-case and optimize vanilla string substitutions? Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list