Use the regex operator | .
grepl(".*(dog.*man|man.*dog).*", x, ignore.case=TRUE)
Use word boundaries if necessary.
grepl(".*(\\bdog\\b.*\\bman\\b|\\bman\\b.*\\bdog\\b).*", x, ignore.case=TRUE)
There is no need to move back and forth .*
grepl("(dog.*man|man.*dog)", x, ignore.case=TRUE)
You can specify a case insensitive modifier inside the regular expression itself.
grepl("(?i)(dog.*man|man.*dog)", x)
source share