I am trying to extract a 'Month, year' substring from a larger string. An example would be:
12345 October, 2019, abc, abcdef
although the length and complexity of the strings surrounding the substring do vary from one record to the next. There will only ever be one 'month, year' substring per string.
So far I have been able to extract the month aspect using the following code:
months <- paste(c("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"), collapse = "|")
str_extract_all("12345 October, 2019, abc, abcdef",months, simplify = FALSE)
While this requires typing out all the months of the year, I don't really want to have to specify every year possible in a similar vector. Is there a way of extracting a set number of characters after a matched string? As in, extract any matching word from the month vector, as well as the next 6 characters (the ', 2019' portion).