I have a variable called summed_EU_Sales, I want to get EU only.
I have tried to do it using gsub this way:
gsub(".*summed_", "", summed_EU_Sales)
which only removes the first summed_. I struggle to remove both of the sides.
>Solution :
Assuming your variable name summed_EU_Sales is actually a string "summed_EU_Sales", we can use regex groupings:
sub(".*_(EU)_.*", "\\1", "summed_EU_Sales")
#> [1] "EU"
Created on 2022-12-19 by the reprex package (v2.0.1)