Convenience operators for regular-expression matching, inspired by SQL's
LIKE. Each takes a character vector x and a single pattern, and
returns a logical vector the same length as x.
%rlike% matches case-insensitively, equivalent to
grepl(pattern, x, ignore.case = TRUE).
%perl% matches case-sensitively using Perl-compatible regular
expressions, equivalent to grepl(pattern, x, perl = TRUE).
Author
Ben Wiseman, benjamin.h.wiseman@gmail.com
Examples
x <- c("foo", "bar", "dOe", "rei", "mei", "obo")
# case-insensitive: where x contains an "o" (any case)
x[x %rlike% "O"]
#> [1] "foo" "dOe" "obo"
# [1] "foo" "dOe" "obo"
# case-sensitive Perl matching: middle letter is an upper-case "O"
x[x %perl% "[a-z]O[a-z]"]
#> [1] "dOe"
# [1] "dOe"