[Tutor] substitute using re.sub

kumar s ps_python at yahoo.com
Tue Oct 24 20:23:35 EDT 2017


Hi group, I am trying to substitute in the following way and i cannot. Could you point out whats wrong in what i am doing. 

>>> z'.|D'
>>> re.sub(z,'1',z)'111'
I just want only  '1' and not '111'. 
I want:>>> re.sub(z,'1',z)'1'
re.sub is repeatedly inserting 3 times because z has .|D . How can I substitute only 1. 
ThanksKumar


More information about the Tutor mailing list