我将文本文件导入到r中,并且正在使用一个函数,该函数确定句点的句号以句点结尾,然后以空格隔开。.
某些句点在句点后没有空格,因此我尝试编写可解决此问题的正则表达式。正则表达式必须特定于后跟单词(不是数字)的句点,因此它不会在小数点后插入空格。
我在下面的示例中尝试使用此正则表达式,但是可以用空格替换句点之后的第一个字母。我正在尝试在句号和下一个单词之间添加空格而不删除。
谢谢
x = " In water, the hydrogen atoms are close to two corners of a tetrahedron centered on the oxygen.At the other two corners are lone pairs of valence electrons that do not participate in the bonding.In a perfect tetrahedron, the atoms would form a 109.5° angle."
gsub("\\.([A-Za-z])", ". ", x)
您可以使用正向前瞻,这样您就不会错过句点之后的第一个字母。
gsub("\\.(?=[A-Za-z])", ". ", x, perl = TRUE)
#" In water, the hydrogen atoms are close to two corners of a tetrahedron
#centered on the oxygen. At the other two corners are lone pairs of valence
#electrons that do not participate in the bonding. In a perfect
#tetrahedron, the atoms would form a 109.5° angle."
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句