I'm trying to create rules for a sentence that contains "dog" but not "cat". I would like the function to return FALSE since the string contains both "dog" and "cat".
Using negation:
grepl("cat.*[^dog]", "asdfasdfasdf cat adsfafds dog", perl=T)
Using negative lookahead:
grepl("cat.*(?!dog)", "asdfasdfasdf cat adsfafds dog", perl=T)
Using str_detect function in the stringr package
require(stringr)
str_detect("asdfasdfasdf cat adsfafds dog", "cat.*(?!dog|$)")
All these three methods return true.