3
我想刪除單詞中字母/特殊字符數量同時出現兩次以上的單詞。正則表達式刪除單詞,如果它在R中同時多次包含字母/特殊字符
EG的輸入是一樣
"Google in theee lland of whhhat c#, c++ and e###"
和輸出應該是
"Google in lland of c#, c++ and"
我想刪除單詞中字母/特殊字符數量同時出現兩次以上的單詞。正則表達式刪除單詞,如果它在R中同時多次包含字母/特殊字符
EG的輸入是一樣
"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?
只是捕獲同一單詞中的前後字符以及緊跟在單詞後面的任何單個空格。