I have text strings like this:
u <- "she goes ~Wha::?~ and he's like ~↑Yeah believe me!~ and she's etc."
What I'd like to do is replace all characters occurring between pairs of ~ delimitors (including the delimitors themselves) by, say, X.
This gsub method replaces the substrings between ~-delimitor pairs with a single X:
gsub("~[^~]+~", "X", u)
[1] "she goes X and he's like X and she's etc."
However, what I'd really like to do is replace each and every single character between the delimitors (and the delimitors themselves) by X. The desired output is this:
"she goes XXXXXXXXX and he's like XXXXXXXXXXXXXXXXXXX and she's etc."
I've been experimenting with nchar, backreference, and paste as follows but the result is incorrect:
gsub("(~[^~]+~)", paste0("X{", nchar("\\1"),"}"), u)
[1] "she goes X{2} and he's like X{2} and she's etc."
Any help is appreciated.