quotes at the edges of a triple quote string...

Peter Hansen peter at engcorp.com
Sat May 1 12:18:10 EDT 2004


Anthony Roberts wrote:

> property = re.compile("""(?P<name>[a-z0-9_\-]+)="(?P<value>.*?)""""re.I)
> 
> This doesn't work because the closing quote in my regex forms the first 
> quote of a triple quote to end the string...
> 
> property = re.compile("""(?P<name>[a-z0-9_\-]+)=("(?P<value>.*?)")""", 
> re.I)
> 
> This mucks up stuff I want to do later.
> 
> I've thought about it for a while, and except for changing it to a 
> single-quoted string with escaped quotes, is there any clean way to do 
> this?

Can't you still use a triple-quoted string, but escape the
last quote?

 >>> """test\""""
'test"'

-Peter



More information about the Python-list mailing list