I have the string x <- c("The first apple is good, and the second and third apples are good too")
I want the string y to be "The first , and the second and third too".
I tried the code y <- str_remove_all(x, "apple.+good"), but it yield
"The first too"
The ? after the + makes it "non-greedy", matching the minimum length.
library(stringr)
x <- c("The first apple is good, and the second and third apples are good too")
y <- str_remove_all(x, "apple.+?good")
y
#> [1] "The first , and the second and third too"