Python 如何在所有大写单词后替换句点?
我正在处理一个需要清理的文本数据集,我需要替换一个特定的模式集。也就是说,我需要在len>1的单词后面用冒号替换句号,这些单词只包含大写字母 我已经尝试过使用正则表达式,但是我不能让它只替换句点 理想情况下,我希望有一个函数执行以下操作: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
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.