Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 句点后带数字字符的分句_Python_Regex_Python 3.x_Split - Fatal编程技术网

Python 句点后带数字字符的分句

Python 句点后带数字字符的分句,python,regex,python-3.x,split,Python,Regex,Python 3.x,Split,我正在使用python3,尝试在句点后拆分带有注释编号的文本: text = "Reproduction now becomes posited as “natural” production.16 Fortunati joins Marx in a minute but crucial declension from usevalue to nonvalue. " 这是我见过的最接近句子分割的正则表达式,仍然有效: sentences = re.split(r' *[\.\?!][\'"\)

我正在使用python3,尝试在句点后拆分带有注释编号的文本:

text = "Reproduction now becomes posited as “natural” production.16 Fortunati joins Marx in a minute but crucial declension from usevalue to nonvalue. "
这是我见过的最接近句子分割的正则表达式,仍然有效:

sentences = re.split(r' *[\.\?!][\'"\)\]]* +', text)
我基本上不知道如何通过正则表达式在一段时间后立即捕获数值实例。是否有助于将[0-9]正确合并到表达式中?谢谢

编辑这是理想的分割方式:

sentences[0]= "Reproduction now becomes posited as “natural” production.16"
sentences[1]= " Fortunati joins Marx in a minute but crucial declension from usevalue to nonvalue."
使用:

如果您可以使用第三方模块,则可以使用允许非固定宽度环视断言的空字符串拆分:

>>> import regex
>>> regex.split(r'(?<=\.\d+\b)', text, flags=regex.VERSION1)
['Reproduction now becomes posited as “natural” production.16',
 ' Fortunati joins Marx in a minute but crucial declension ...']
导入正则表达式 >>>正则表达式拆分(r'(?使用:

如果您可以使用第三方模块,则可以使用允许非固定宽度环视断言的空字符串拆分:

>>> import regex
>>> regex.split(r'(?<=\.\d+\b)', text, flags=regex.VERSION1)
['Reproduction now becomes posited as “natural” production.16',
 ' Fortunati joins Marx in a minute but crucial declension ...']
导入正则表达式
>>>正则表达式拆分(r'(?你能清楚地告诉我们那句话的期望输出吗?类似这样的东西可能会起作用:
\.\d+\b
,但不清楚这是否是你想要的。注意,用更多的信息更新了这篇文章,尝试将最后一个
+
更改为
*
,以使空格成为可选的。但是,这可能会影响拆分其他字符串。你能吗清楚地向我们展示该句子所需的输出?类似这样的内容可能会起作用:
\.\d+\b
,但不清楚这是否是您想要的。注意,用更多的信息更新了帖子尝试将最后一个
+
更改为
*
,以使空格成为可选的。但是,这可能会影响拆分其他字符串。