get back my simple little string after re search and replace

Gontrand Trudau cesium5500 at
Wed Jan 13 06:12:31 CET 2010


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']

I used Kodos (version 2.4.9) under ubuntu 9.04 to get this code :

import re

# common variables

rawstr = r"""\s*\;"""
embedded_rawstr = r"""\s*\;"""
matchstr = """email at                                  
;email at                               ;name, 
firstname                ;info;2010-01-01T00:00:00"""

# method 1: using a compile object
compile_obj = re.compile(rawstr)
match_obj =

# method 2: using search function (w/ external flags)
match_obj =, matchstr)

# method 3: using search function (w/ embedded flags)
match_obj =, matchstr)

# Replace string
newstr = compile_obj.subn('','', 0)

By the way I use Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
under ubuntu.

My objective is to remove all the white space except the one between the 
name and the firstname, that is OK.

I understand that re.compile compile my re stored in rawstr... match_obj 
return : <_sre.SRE_Match object at 0xb7777c28> that mean there were a 
match... I can extract information from this objet in a couple of way 
with : or match_obj.start...

Sorry to be a newbie who is trying to make something easy but just felt 
on technical programmer stuff... :-)

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

Thank you


More information about the Python-list mailing list