I'm very new to regular expressions, so my apologies if this is an obviously stupid question.
Suppose I have a string of the form (c"fair*", "beaut*") and I want to replace the asterisk (*) at the end by a caret (^) at the beginning: c("^fair", "^beaut"). How could I go about doing that using stringr? I have read this excellent introduction to regexp, but did not figure it out. I made several attempts with stringr::str_replace_all(), to no avail. The issue seems to be that the replacement in stringr::str_replace_all() can't be a regexp. Is that so? If yes, is there any other way to do this?
library(stringr)
x <- c("fair*", "beaut*")
str_replace_all(x, "\\*", "^\\^")
#> [1] "fair^^" "beaut^^"
str_replace_all(x, "\\*", "^\\^")
#> [1] "fair^^" "beaut^^"
str_replace_all(x, "\\*", "\\^*")
#> [1] "fair^*" "beaut^*"
str_replace_all(x, "\\*", "\\^(*)")
#> [1] "fair^(*)" "beaut^(*)"
Created on 2021-09-15 by the reprex package (v2.0.1)