Apr-26-2019, 07:50 AM
My code doesn't recognize "Kind Regards" at all on it's own, it only removes it when it is next to "Vriendelike groete" :
import re from bs4 import BeautifulSoup import string message = ''' Dear Sir What do you think Kind regards Badu Thusong Direct tel: 021 974 7313 | Email: [email protected] Good Morning We need your input please. Vriendelike groete/ Kind regards Badu Thusong Direct tel: 021 974 7313 | Email: [email protected] Dear Boss How are you today Your number Branch Agency: Meme Branch Agency Code: 0329271 Thank you for contacting us Kind regards Agriculture Contact Centre ''' for phrase in ['Vriendelike groete/Kind regards', 'Vriendelike groete/ Kind regards']: text = message.replace(phrase, '') print(text)Output:
Output:Dear Sir
What do you think
Kind regards
Badu Thusong
Direct tel: 021 974 7313 | Email:
[email protected]
Good Morning
We need your input please.
Badu Thusong
Direct tel: 021 974 7313 | Email:
[email protected]
Dear Boss
How are you
today
Your number
Branch Agency: Meme
Branch Agency Code: 0329271
Thank you for contacting us
Kind regards
Agriculture Contact Centre
(Apr-26-2019, 07:08 AM)perfringo Wrote: My mistake - the order should be reversed, otherwise 'Kind regards' will be replaced on first loop and second phrase will not be matched (as 'Kind regards' part is already removed).
In [1]: message = '\nGood Morning\n\nWe need your input please.\n\n\nVriendelike groete/ Kind regards\n\nBadu Thusong\n\nDirect tel: 021 974 7313 | Email:\nBadu@thus ...: ong.com\n\n\nDear Boss\n\n\nHow are you\n\ntoday\n\nYour number\n\nBranch Agency: Meme\n\nBranch Agency Code: 0329271\n\nThank you for contacting us\n\n\nKin ...: d regards\n\nAgriculture Contact Centre' In [2]: for phrase in ['Vriendelike groete/ Kind regards', 'Kind regards']: ...: message = message.replace(phrase, '') ...: In [3]: message Out[3]: '\nGood Morning\n\nWe need your input please.\n\n\n\n\nBadu Thusong\n\nDirect tel: 021 974 7313 | Email:\[email protected]\n\n\nDear Boss\n\n\nHow are you\n\ntoday\n\nYour number\n\nBranch Agency: Meme\n\nBranch Agency Code: 0329271\n\nThank you for contacting us\n\n\n\n\nAgriculture Contact Centre'