Test a pattern in strings, and return boolean.

Usage

re2_detect(string, pattern, anchor = UNANCHORED, parallel = FALSE, grain_size = 1e+05, ...)

Arguments

string
a character vector
pattern
a character vector or pre-compiled regular expressions
anchor
see UNANCHORED
parallel
use multithread
grain_size
a minimum chunk size for tuning the behavior of parallel algorithms
...
further arguments passed to re2

Value

A logical vector.

Description

Test a pattern in strings, and return boolean. Vectorised over strings and patterns.

Examples

re2_detect("one", "(o.e)")
[1] TRUE
re2_detect("123-234-2222", "\\d\\d\\d-\\d\\d\\d-\\d\\d\\d\\d")
[1] TRUE
words = c("sunny","beach","happy","really") re2_detect(words, "y")
[1] TRUE FALSE TRUE TRUE
re2_detect(words, "^b")
[1] FALSE TRUE FALSE FALSE
re2_detect(words, "[abc]")
[1] FALSE TRUE TRUE TRUE
# vectorize (res = re2_detect("This", letters))
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE [25] FALSE FALSE
letters[res]
[1] "h" "i" "s"
letters[re2_detect("This", letters, case_sensitive = FALSE)]
[1] "h" "i" "s" "t"
letters[re2_detect("This", re2(letters, case_sensitive = FALSE))]
[1] "h" "i" "s" "t"
# In stringi, "" empty search patterns return NA. # In re2r, empty search patterns will match # empty string. re2_detect("abc", "")
[1] TRUE
stringi::stri_detect("abc", regex = "")
Warning message: empty search patterns are not supported
[1] NA