get back my simple little string after re search and replace

Gabriel Genellina gagsl-py2 at
Wed Jan 13 10:03:37 CET 2010

En Wed, 13 Jan 2010 02:12:31 -0300, Gontrand Trudau <cesium5500 at>  

> I have read the python doc pretty much, played around with python code,  
> but unable to get back my "string" after made my replacement with python  
> RE
> Here my string :
> ['email at                                   
> ;email at                               ;name,  
> firstname                ;info;2010-01-01T00:00:00']
> My objective is to remove all the white space except the one between the  
> name and the firstname, that is OK.

Is it enough to remove all whitespace preceding a ';'?

py> text = "email at                                  ;email at
                         ;name, firstname                 
py> import re
py> re.sub('\s+;', ';', text)
'email at;email at;name, firstname;info;2010-01-01T00:00:00'

> I would just like to be able to do something like that :
> print match_obj
> and have the result of the modification I just did :
> email at','email at','name,  
> firstname','info','2010-01-01T00:00:00

Those single quotes are confusing -- they aren't in the original string as  
you posted it... Apart from that, my solution worked fine in this example.

Gabriel Genellina

More information about the Python-list mailing list