I am finding patterns within a large text file, then I remove the patterns, and print the text. But, I am trying to replace the old text within the file (with the patterns) with the new_text
without the patterns.
Im using the regex package, and no matter what i try it doesnt work
My command .replace
is not working.
import re
rgx_list = ['Read More',
'Read',
'And follow us on Twitter to keep up with the latest news and and acute and primary Care.',...]
txt_path = '/Users/sofia/Documents/src/fakenews1/data/news-data/war_sc_r.txt'
with open(txt_path) as new_txt_file:
new_text = new_txt_file.read()
for rgx_match in rgx_list:
new_text = re.sub(rgx_match, '', new_text)
new_text.replace(txt_path, new_text)
print(new_text)
Thank you !