I'm trying to repair broken email records in a table. There are emails, for example: 'google@google.comyahoo@yahoo.com' but there can be a single email like 'google@google.com'. The best way to make this correct is in my opinion to use re.sub. But there is a little problem. If there is a record:
email = 'google@google.comyahoo@yahoo.com'
I can't simply do replace('.com','.com, ') because it affects both '.com' substrings. So I want to use re.sub('.com\w', '.com, \w',email) which replaces only those '.com' substrings, which aren't in the end of the record. The problem is that I want to keep a \w value there.
print re.sub('.com\w', '.com, \w',email)
>>> google@google.com, \wahoo@yahoo.com
instead of
>>> google@google.com, yahoo@yahoo.com
Can anybody give me an advice how to make it work? (I want to separate emails by comma and space)
Aucun commentaire:
Enregistrer un commentaire