I am trying to remove two patterns using
str_replace in R.
The patterns that I would like to remove are
I first tried:
> variables <- c("1_SmallBaskets", "2_Medium", "3_High")
> str_replace(variables, "Baskets|\\d+_", "")
 "SmallBaskets" "Medium" "High"
As far as I can make out, as the pattern
\\d+_ comes first this is replaced but then it moves onto the next without replacing the
I then tried making the expression greedy (example below), but this seems to only be checking for the expression
> str_replace(variables, "Baskets|\\d+_/g", "")
 "1_Small" "2_Medium" "3_High"
I have tested that the syntax
Small|High works, i.e. replaces Small or High, so I don't understand why when trying to replace a digit and a character the same logic doesn't apply