I have a text full of adverbes and it's replacements like this :
adverbe1 |replacement1
adverbe2 |replacement2
adverbe3 |replacement3
And i want the adverbes to replaced in my text:
Example :
'Hello adverbe1 this is a test' to be this : 'Hello replacement1 this is a test'
but am runing out of solutions, my code so far:
adverbes = open("list_adverbes_replacement.txt", encoding="utf-8")
list_adverbes = []
list_replacement = []
for ad in adverbes.readlines():
if ad != '' and ad.split('|')[0].strip(' ')[-3:] == 'ent':
list_adverbes.append(ad.split('|')[0].strip(' '))
list_replacement.append(ad.split('|')[1])
pattern = r"(\s+\b(?:{}))\b".format("|".join(list_adverbes))
data = re.sub(pattern, r"\1", data)
I couldn't find a way to replace each adverbes with the appropriate replacement.
the list_adverbes_replacement.txt
is the text i gave in the beginning, and please am looking for a regex solution, i just don't know what am missing.