Substitution with Hash Values

Jon Ribbens jon+usenet at unequivocal.co.uk
Sat Apr 20 10:37:34 EDT 2002


In article <mailman.1019303438.1339.python-list at python.org>, holger krekel wrote:
>> Need a raw string there, i.e.
>> 
>>   r"\{\{(.*?)\}\}"
> 
> yes, i am sometimes confused by 'raw strings' and 'strings'. 
> Could you help by saying why exactly it is needed here?

Hmm, well, actually you don't, since \{ is not a string literal escape
sequence and Python is weird and leaves in unknown escape sequences
unchanged.

Basically, you always use raw strings when using regexps, and never
use them anywhere else. You need them because both string literals and
regexps treat \ as an escape character, so to get the \ through to the
regexp unchanged you use a raw string.



More information about the Python-list mailing list