我想删除那些单词中字母/特殊字符数同时出现两次以上的单词。
例如,输入就像
"Google in theee lland of whhhat c#, c++ and e###"
并且输出应该是
"Google in lland of c#, c++ and"
最佳答案
x <- "Google in theee lland of whhhat c#, c++ and e###"
gsub("\\S*(\\S)\\1\\1\\S*\\s?", "", x)
# [1] "Google in lland of c#, c++ and "
(\\S)\\1\\1
查找单个非空格字符的三个连续重复序列。周边
\\S*
和 \\S*\\s?
只需捕获同一个单词中的前后字符,以及紧跟在该单词之后的任何单个空格。
关于正则表达式删除单词,如果它在 R 中同时多次包含字母/特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22888528/