I am balancing several versions of R and want to change my R libraries loaded depending on which R and which operating system I\'m using. As such, I want to stick with base
You could do
txt <- c("foo release 123", "bar release", "foo release 123 bar release 123") pattern <- "release ([0-9]+)" stringr::str_extract(txt, pattern) # [1] "release 123" NA "release 123" sapply(regmatches(txt, regexec(pattern, txt)), "[", 1) # [1] "release 123" NA "release 123"