I have a partial date string
partial <- "UN-Jan-2022"
My desired output
> parital
Jan
I’m trying to do this by using gsub, I can remove "UN-" or -"2022" but not sure how to remove both in one gsub
gsub("UN-", "", partial)
Jan-2022
gsub("-2022", "", partial)
UN-Jan
>Solution :
Another gsub option which extracts everything between both "-" like this:
partial <- "UN-Jan-2022"
gsub(".*-(.*)\\-.*", "\\1", partial)
#> [1] "Jan"
Created on 2022-07-27 by the reprex package (v2.0.1)