句子将是一系列字符:
我有一个包含以下文本的文件:
this is the\nfirst sentence. Isn't\nit? Yes ! !! This \n\nlast bit :) is also a sentence, but \nwithout a terminator other than the end of the file\n
根据上述定义,其中有四个“句子”:
this is the\nfirst sentence
Isn't\nit
Yes
This \n\nlast bit :) is also a sentence, but \nwithout a terminator other than the end of the file
请注意:
这就是我目前拥有的(.*\n+)
,我不知道如何改进它。你知道吗
请我需要你的帮助,一个正则表达式,解构成上面的文字,并返回一个列表。事先感谢你的帮助。你知道吗
下面的内容不是每个人都适用的,但它适用于您的特定输入。您可以进一步调整此表达式:
参见regex demo。你知道吗
详细信息:
([^!?.]+)
-捕获组1匹配除!
、?
、.
以外的1个或多个字符[!?.\s]*
-0或更多!
,?
,.
,空格(?![!?.])
-后面不跟!
、?
或.
。你知道吗在Python中,您需要将它与
re.findall
一起使用,后者只获取捕获组捕获的子字符串:见Python demo
试试这个:
相关问题 更多 >
编程相关推荐