G
Gontrand Trudau
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 :
['(e-mail address removed)
;[email protected] ;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 = """(e-mail address removed)
;[email protected] ;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 :
(e-mail address removed)','(e-mail address removed)','name, firstname','info','2010-01-01T00:00:00
Thank you
Gontrand
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 :
['(e-mail address removed)
;[email protected] ;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 = """(e-mail address removed)
;[email protected] ;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 :
(e-mail address removed)','(e-mail address removed)','name, firstname','info','2010-01-01T00:00:00
Thank you
Gontrand