str_replace doesn't replace all occurrences, but gsub does?

后端 未结 1 1821
灰色年华
灰色年华 2021-01-18 03:33

I am trying to remove brackets from a string like the one below.

library(stringr)

x <- \"(Verhoeff,1937)\"

str_replace(string = x, pattern = \"(\\\\()|(         


        
相关标签:
1条回答
  • 2021-01-18 03:44

    It only matches the first occurency, whereas gsub does it all. Use str_replace_all instead:

    str_replace(string = "aa", pattern = "a", replacement = "b") # only first
    
    str_replace_all(string = "aa", pattern = "a", replacement = "b") # all
    
    0 讨论(0)
提交回复
热议问题