
Return which regular expression of several matches a character value
Source:R/which_regex_matches.R
which_regex_matches.RdReturn which regular expression of several matches a character value
Usage
which_regex_matches(
pattern,
x,
ignore.case = FALSE,
perl = TRUE,
fixed = FALSE,
useBytes = FALSE
)Arguments
- pattern
The character vector with regular expressions to match against
- x
The text to match against the regular expressions
- ignore.case
Whether to be case sensitive (see
base::grepl()).- perl
Whether
patternspecifies Perl regexes (seebase::grepl()).- fixed
Whether
patternis a regex or fixed string (seebase::grepl()).- useBytes
See
base::grepl().
Examples
pattern <-
c("[0-9]",
"[A-Z]",
"[a-z]");
rock::which_regex_matches(
pattern,
"42"
);
#> [0-9] [A-Z] [a-z]
#> TRUE FALSE FALSE
rock::which_regex_matches(
pattern,
"forty-two"
);
#> [0-9] [A-Z] [a-z]
#> FALSE FALSE TRUE
rock::which_regex_matches(
pattern,
c(42, "forty-two")
);
#> 42 forty-two
#> [0-9] TRUE FALSE
#> [A-Z] FALSE FALSE
#> [a-z] FALSE TRUE