I have a text like this:
text = 'I love apple, pear, grape and peach'
If I want to know if the text contain either apple
or pear
. I can do the following and works fine:
str_detect(text,"apple|pear")
[1] TRUE
my question is what if I want to use boolean like this (apple OR pear) AND (grape)
.
Is there anyway that I can put it in str_detect()
. Is that possible?
The following is NOT working:
str_detect(text,"(apple|pear) & (grape)" )
[1] FALSE
The reason I want to know this is I want to program to convert a 'boolean query' and feed into the grep
or str_detect
. something like:
str_detect(text, '(word1|word2) AND (word2|word3|word4) AND (word5|word6) AND .....')
The number of AND
varies....
No solution with multiple str_detect
please.