I want to remove the last section of an article (i.e. References section) in a .txt file using Python. By "the whole section" I mean everything after the word "References":
Is there a way to remove all the content after the word "References" using regex or any other methods?
I have tried the following code, however, it only removes the first line after the word "References":
input_file = open("remove.txt", 'r', encoding= 'utf-8')
prev_line = False
lines =[]
for line in input_file:
if not prev_line:
lines.append(line)
prev_line=False
if "References" in line:
prev_line=True
input_file.close()
input_file = open("input.txt", 'w')
for line in lines:
input_file.write(line)
input_file.close()
Thank you
