I have a vector of strings. Most of the elements in the vector consist of one or more letters followed by one or more numbers. I wish to selectively replace only the words with "September" (and its abbreviations) in each string with "Sep" but retain the numbers. This is what I have tried out using stringr package
my.data <- c("01Sept2019", "05sep2019", "4September2019", "8sep2019",
"12oct2019", "4Jun2018", "17Mar2017", "09May2015", "13Sep19")
library(stringr)
my.data %>% str_replace_all("(?i)Sept?(ember)?[0-9]", "Sep")
#> [[1]]
#> [1] "01Sep019", "05Sep019", "4Sep019", "8Sep019", "13Sep9"
This is what I would like to obtain:
#> [1] "01Sep2019", "05Sep2019", "4Sep2019", "8Sep2019", "13Sep19"
Can someone please help me out. Thanks