Performs multiple grepl
string pattern matches over a character vector
and returns a logical vector indicating whether each element matches
any or all of the given patterns.
grepl_multi(x, desc, intersect = FALSE)
Arguments
- x
A character vector of regular expression patterns to match.
- desc
A character vector to search within.
- intersect
Logical; if FALSE
(default), returns TRUE
for any match
(union behavior). If TRUE
, returns TRUE
only for elements that match all patterns
(intersection behavior).
Value
A logical vector of the same length as desc
indicating which elements match
the specified patterns according to the intersect
setting.
Examples
strings <- c("apple pie", "banana split", "cherry tart", "apple tart")
grepl_multi(c("apple", "tart"), strings) # OR behavior
#> [1] TRUE FALSE TRUE TRUE
grepl_multi(c("apple", "tart"), strings, TRUE) # AND behavior
#> [1] FALSE FALSE FALSE TRUE