Hi,

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 :

['em...@msn.com ;em...@msn.com ;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 = """em...@msn.com ;em...@msn.com ;name, firstname ;info;2010-01-01T00:00:00"""

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

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

# method 3: using search function (w/ embedded flags)
match_obj = re.search(embedded_rawstr, 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 : match_obj.group 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 :

em...@msn.com','em...@msn.com','name, firstname','info','2010-01-01T00:00:00

Thank you

Gontrand
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to