I'm trying to split a text file into sentences, using punctuation as a delimiter. The code I have so far works but the delimiter is being printed out on a line by itself. How can I keep the punctuation together with the sentence?
import re
string = ""
with open("text.txt") as file:
for line in file:
for l in re.split(r"(\. |\? |\! )",line):
string += l + "\n"
print(string)
Example output:
This is the flag of the Prooshi — ous, the Cap and Soracer
.
This is the bullet that byng the flag of the Prooshious
.
This is the ffrinch that fire on the Bull that bang the flag of the Prooshious
.