Reputation: 65
I have a vcard string : I want to delete a line from this string , for example line related to TEL but when i use replace method , an empty line is left , how to delete the full line without leaving an empty line ?
vcard = """ BEGIN:VCARD
VERSION:3.0
UID:00000xcdfgedgrerfgrg
N:LastName;FirstName;;;
TEL;CELL:00000000 EMAIL:[email protected]
END:VCARD
"""
Upvotes: 0
Views: 41
Reputation: 33335
If you want to delete the entire line, then you have to replace the entire line, including leading spaces and the newline the end:
vcard = vcard.replace(' TEL;CELL:00000000 EMAIL:[email protected]\n', '')
Upvotes: 0
Reputation: 80
Try this:
import re
vcard = """ BEGIN:VCARD
VERSION:3.0
UID:00000xcdfgedgrerfgrg
N:LastName;FirstName;;;
TEL;CELL:00000000 EMAIL:[email protected]
END:VCARD
"""
re.sub(".*TEL.*\n?","",vcard)
Upvotes: 3