我有一个字符串,它们之间带有数字字符。
TestString = "white tiger roars.12.03.001-fast horse runs13.15.01.001-cat is useless 11.01.09.001-dog barks22.07.01.001"
我想看起来像
"white tiger roars-fast horse runs-cat is useless-dog barks"
到目前为止,我无法保留单词之间的空间。
gsub("[^a-z-]", "", TestString)
#"whitetigerroars-fasthorseruns-catisuseless-dogbarks"
答案 0 :(得分:1)
gsub("\\s?(\\d+|\\.)","","white tiger roars.12.03.001-fast horse runs13.15.01.001-cat is useless 11.01.09.001-dog barks22.07.01.001")
[1] "white tiger roars-fast horse runs-cat is useless-dog barks"