How can I use str_match to extract the remaining string after the last substring.
For example, for the string "apples and oranges and bananas with cream", I'd like to extract the remainder of this string after the last occurrence of " and " to return "bananas with cream".
I have tried many alternatives to this command but it either keeps returning the remainder of the string after the first "and" or an empty string.
library(stringr)
str_match("apples and oranges and bananas with cream", "(?<= and ).*(?! and )")
# [,1]
#[1,] "oranges and bananas with cream"
I've searched StackOverflow for solutions and found some for javascript, Python and base R but have found none for stringr package.
Thanks.