简体   繁体   English

找到并用正确的句子替换以小写字母开头的句子。 正则表达式或崇高

[英]find and replace with correct sentence case sentences starting with lowercase. regex or sublime

I have text where some sentences start with lowercase.我有一些句子以小写开头的文本。 i need to find them and replace with correct sentence case.some punctuations are incorrect.我需要找到它们并用正确的句子替换。一些标点符号不正确。 ie sentence starting after full stop without space.即句号后开始没有空格的句子。

ie IE

.this sentence
and this.also this. and this.This one is not.

replace with ->替换为 ->

.This sentence
And this.Also this. And this.This one is not.

sublime text 3 solution, regex , or python nltk solution is suitable. sublime text 3 解决方案、regex 或 python nltk 解决方案是合适的。

i tried this solution.我试过这个解决方案。 but it is slow and does not find sentences without space after full stop.但它很慢,句号后找不到没有空格的句子。

import nltk.data
from nltk.tokenize import sent_tokenize
text = """kjdshkjhf. this sentence
and this.also this. and this. This one is not."""

aa=sent_tokenize(text)
for a in aa:
    if (a[0].islower()):
        print a
        print "****"

You can use this pattern你可以使用这个模式

^([^a-zA-Z]*)([a-z])

在此处输入图片说明

and use $1\\U$2 as substitution并使用$1\\U$2作为替代

Regex Demo

Update:- If you want to capture first lowercase after each .更新:-如果您想在每个. ( period ) you can use this (句号)你可以用这个

^([^a-zA-Z]*)([a-z])|(\.\s*)([a-z])

Demo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM