Count the number of matches in a string.

Usage

re2_count(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

An integer vector.

Description

Count the number of matches in a string. Vectorised over strings and patterns.

Examples

re2_count("one", "(o.e)")
[1] 1
re2_count("123-234-2222", "\\d\\d\\d-\\d\\d\\d-\\d\\d\\d\\d")
[1] 1
words = c("sunny","beach","happy","really") re2_count(words, "y")
[1] 1 0 1 1
re2_count(words, "^b")
[1] 0 1 0 0
re2_count(words, "[abc]")
[1] 0 3 1 1
# vectorize re2_count("This", letters)
[1] 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0