我想删除下面句子中的“amp”一词。
original:
x <- 'come on ***amp*** this just encourages the already rampant mispronunciation of phuket'
我想要的是:
x <- 'come on this just encourages the already rampant mispronunciation of phuket'
但是,如果我使用gsub
,“rampant”一词中的“amp”也将被删除,这不是我想要的情况。我能知道在这种情况下我应该使用什么功能吗?
> gsub("amp","", x)
[1] "come on this just encourages the already rant mispronunciation of phuket"
您可以使用这个正则表达式:
gsub("\\bamp\\b","", x)
# [1] "come on this just encourages the already rampant mispronunciation of phuket"
The \\b
表示单词边界。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)