【发布时间】:2015-04-17 21:10:21
【问题描述】:
我在 R 中为精确的字符串匹配而苦苦挣扎。我只需要在句子中与搜索的字符串完全匹配:
sentence2 <- "laptop is a great product"
words2 <- c("top","laptop")
我正在尝试这样的事情:
sub(paste(c("^",words2,"$")),"",sentence2)
我只需要用空字符串替换笔记本电脑 - 完全匹配(笔记本电脑)但没有用...
拜托,你能帮帮我吗?提前致谢。
期望的输出:
is a great product
【问题讨论】:
标签: regex r string-matching