get back my simple little string after re search and replace
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Wed Jan 13 04:03:37 EST 2010
En Wed, 13 Jan 2010 02:12:31 -0300, Gontrand Trudau <cesium5500 at yahoo.ca>
escribió:
> 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 msn.com
> ;email at msn.com ;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 msn.com ;email at msn.com
;name, firstname
;info;2010-01-01T00:00:0
0"
py> import re
py> re.sub('\s+;', ';', text)
'email at msn.com;email at msn.com;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 msn.com','email at msn.com','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