Regular expressions newbie: something for templates

Darrell dgallion1 at yahoo.com
Sun Mar 10 18:55:29 EST 2002


>>> s="This is the test $var1$ and this is $var2$"
>>> import re
>>> re.sub("\$(.*?)\$","%(\g<1>)s",s)
'This is the test %(var1)s and this is %(var2)s'
>>>

--Darrell


Thomas Weholt wrote:

> Hi,
> 
> I'm not getting the hang of regular expressions. All I want to do is this.
> 
> Take string #1 :
> 
> "This is the test $var1$ and this is $var2$"
> 
> and turn it into
> 
> "This is the test %(var1)s and this is %(var2)s"
> 
> Any clues?
> 
> ( And yes, yet another template system in the works ;-) )
> 
> Thomas




More information about the Python-list mailing list