为什么gsub不能按预期工作

时间:2014-06-20 10:27:48

标签: regex r gsub

我有这个字符串:

c <- "thethirsty thirsty itthirsty (thirsty) is"

我希望输出为

     "thethirsty thirsty itthirsty no is"

这就是我想要的。

gsub(" (thirsty) ", " no ", c)

这就是我所得到的。为什么不起作用?并建议另一种方法。

"thethirsty no itthirsty (thirsty) is" 

1 个答案:

答案 0 :(得分:1)

默认情况下,gsub将第一个参数解释为正则表达式。您不希望这样,应该设置fixed=TRUE

gsub(" (thirsty) ", " no ", c, fixed=TRUE)
#[1] "thethirsty thirsty itthirsty no is"
相关问题