python - Creating new lines with full stops (period) in text files -


i have sentence in text file want display in python, want display after every full stop(period) new line starts.

for example paragraph

"dr. harrison bought bargain.co.uk 2.5 million pounds, i.e. paid lot it. did mind? john smith, esq. thinks didn't. nevertheless, isn't true... well, probability of .9 isn't." 

but want display following

"dr. harrison bought bargain.co.uk 2.5 million pounds, i.e. paid lot it.  did mind? john smith, esq. thinks didn't.  nevertheless, isn't true...  well, probability of .9 isn’t." 

this made increasingly difficult other periods appear in sentence, such in website address, 'dr.', 'esq.' '.9' , of course first 2 dots in ellipsis.

i not sure how approach regards other periods exist in text file, can help? thank you.

"your task write program given name of text file able write content each sentence on separate line." <-- task set

this job on text:

text = "dr. harrison bought bargain.co.uk 2.5 million pounds, i.e. "\        "paid lot it. did mind? john smith, esq. thinks didn't. "\        "nevertheless, isn't true... well, probability of .9 "\        "isn't."  import re  pat = ('(?<!dr)(?<!esq)\. +(?=[a-z])') print re.sub(pat,'.\n',text) 

result

dr. harrison bought bargain.co.uk 2.5 million pounds, i.e. paid lot it. did mind? john smith, esq. thinks didn't. nevertheless, isn't true... well, probability of .9 isn't. 

but impossible have regex pattern never fail in such complex thing human writing.
note example obliged put negative lookbehind assertion exclude case of dr. (and did same esq. though doesn't represent problem in text because followed thinks doesn't begin capital letter)
think it's impossibe put similar cases in regex pattern in advance, there untought cases happen 1 day or another.

but code lot of desired job, though. not bad, esteem.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -