Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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_String - Fatal编程技术网

Python 如何在所有大写单词后替换句点?

Python 如何在所有大写单词后替换句点?,python,regex,string,Python,Regex,String,我正在处理一个需要清理的文本数据集,我需要替换一个特定的模式集。也就是说,我需要在len>1的单词后面用冒号替换句号,这些单词只包含大写字母 我已经尝试过使用正则表达式,但是我不能让它只替换句点 理想情况下,我希望有一个函数执行以下操作: s = "this is a CITATION. AUTHOR, information GOES here AnD. this P. period isn't replaced." s = corr(s) s = "this is a CITATION: A

我正在处理一个需要清理的文本数据集,我需要替换一个特定的模式集。也就是说,我需要在len>1的单词后面用冒号替换句号,这些单词只包含大写字母

我已经尝试过使用正则表达式,但是我不能让它只替换句点

理想情况下,我希望有一个函数执行以下操作:

s = "this is a CITATION. AUTHOR, information GOES here AnD. this P. period isn't replaced."
s = corr(s)
s = "this is a CITATION: AUTHOR, information GOES here AnD. this P. period isn't replaced."
但我已经试过了:

import re
s = re.sub(r'[A-Z]+\.',':',s)

将引用本身替换为我不需要的冒号。

使用带单词边界的正则表达式
\b
和量词
{2,}
():

印刷品:

this is a CITATION: AUTHOR, information GOES here AnD. this P. period isn't replaced.

使用带有单词边界
\b
和量词
{2,}
()的正则表达式:

印刷品:

this is a CITATION: AUTHOR, information GOES here AnD. this P. period isn't replaced.