Multiple string.replace in one run

Thomas Güttler guettler at
Fri Jun 20 15:43:57 CEST 2003

John Hunter wrote:

>>>>>> "Thomas" == Thomas Güttler <guettler at> writes:
>     Thomas> I could do this with string.replace, but if I want to
>     Thomas> replace several variables, I need to do the replace
>     Thomas> several times. Since the file could be very long I am
>     Thomas> searching for a better solution.
>     Thomas> How can I replace several variables at once?
> The variable delimiters, eg, '$', were used inconsistently in the
> example you posted 

Sorry, the example was typed into the MUA directly.

>     def mysub(m):
>         return vars[]
>     # a literal dollar sign, followed by anything that isn't a dollar
>     # sign followed by a literal dollar sign
>     print re.sub('\$[^$]+\$', mysub, s)

Thank your for this example. That's was what I was looking for.

More information about the Python-list mailing list