x = "PRODUCT colgate good but not goodOKAY" library(stringr) str_extract(string = x, pattern = perl("(?<=PRODUCT).*(?=OKAY)"))
(?<=PRODUCT) - Take a look behind PRODUCT
.* matches all but newlines.
(?=OKAY) - Look forward to match OKAY .
I must add that you do not need the stingr package for this, the basic functions of sub and gsub work fine. I use stringr for syntax consistency: I retrieve, replace, discover, etc. Function names are predictable and understandable, and the arguments are in sequential order. I use stringr because it saves me having to go to the documentation every time.
source share