backslash plague

Mike Rovner mrovner at propel.com
Fri Oct 22 15:31:33 EDT 2004


Luis P. Mendes wrote:

> I've already read many pages on this but I'm not able to separate the
> string 'R0\1.2646\1.2649\D' in four elements, using the \ as the separator.
> 
> a='R0\1.2644\1.2344\D'

a=r'R0\1.2644\1.2344\D'

> re.sub(r'\'','ff',a)  does nothing

 >>> re.sub(r'\\\\','ff',a)
'R0ff1.2644ff1.2344ffD'

and also

 >>> a.replace('\\','ff')
'R0ff1.2644ff1.2344ffD'

You said, you wanna _split_ them:

 >>> a.split('\\')
['R0', '1.2644', '1.2344', 'D']

HTH,
Mike




More information about the Python-list mailing list