Help with regex search-and-replace (Perl to Python)
schifschaf at gmail.com
Mon Feb 8 04:00:40 CET 2010
On Feb 7, 8:57 am, Tim Chase <python.l... at tim.thechases.com> wrote:
> Steve Holden wrote:
> > Really? Under what circumstances does a simple one-for-one character
> > replacement operation fail?
> Failure is only defined in the clarified context of what the OP
> wants :) Replacement operations only fail if the OP's desired
> output from the above mess doesn't change *all* of the ]/[
> characters, but only those with some form of parity (nested or
> otherwise). But if the OP *does* want all of the ]/[ characters
> replaced regardless of contextual nature, then yes, replace is a
> much better solution than regexps.
I need to do the usual "pipe text through and do various search/
replace" thing fairly often. The above case of having to replace
brackets with braces is only one example. Simple string methods run
out of steam pretty quickly and much of my work relies on using
regular expressions. Yes, I try to keep focused on simplicity, and
often regexes are the simplest solution for my day-to-day needs.
More information about the Python-list