0

I have a variable embeeded in a string, that I need to replace. Tried everything.

enter image description here

I've tried:

`tmp <- tmp %>% mutate(q_text = str_replace(q_text, "$$R01_46_07", "NewText"))
tmp$q_text<- str_replace(tmp$q_text, "$$R01_46_07", "NewText")

I get no error - but also no replacement. Doin' sumthin' dumb. I think the "$$" are preventing this from working. Any help? Thank you!

David Weisser
  • 117
  • 1
  • 10
  • 4
    In regex, `$` is a special character referring to the end of the string. You need to escape it with a double backslash: `str_replace(tmp$q_text, "\\$\\$R01_46_07", "NewText")` or use the `fixed()` function in `stringr` to indicate you want an exact match without special characters, `str_replace(tmp$q_text, fixed("$$R01_46_07"), "NewText")` – Gregor Thomas Apr 25 '23 at 15:01

0 Answers0