I have a line like this:
vect <- c("Thin lines are not great, I am in !!! AND You shouldn't be late OR you loose")
I want to replace "in" with% in% "," AND "with" & "," OR "with" | "
I know that this can be done with gsub as shown below:
gsub("\\bin\\b","%in%", vect),
but I need three different lines for each replacement, so I prefer using gsubfn .
so I tried
gsubfn("\\bin\\b|\\bAND\\b|\\bOR\\b", list("in"="%in%", "AND"= "&", "OR"="|"), vect)
but it returns the string unchanged, for some reason \\b does not work for the string. However, \\b works fine with gsub , and I can replace all three lines inside by concatenating them together using gsub .
My question is: why \\b does not work inside gsubfn . What am I missing inside my regex?
Please, help.
The output should be:
"Thin lines are not great, I am %in% !!! & You shouldn't be late | you loose"
It works:
gsubfn("\\w+", list("in"="%in%", "AND"= "&", "OR"="|"), vect)
regex r gsubfn
PKumar
source share