re2_count: Count the number of matches in a string

View source: R/RcppExports.R

re2_countR Documentation

Count the number of matches in a string

Description

Vectorized over string and pattern. Match against a string using a regular expression and return the count of matches.

Usage

re2_count(string, pattern)

Arguments

string

A character vector, or an object which can be coerced to one.

pattern

Character string containing a regular expression, or a pre-compiled regular expression (or a vector of character strings and pre-compiled regular expressions).
See re2_regexp for available options.
See re2_syntax for regular expression syntax.

Value

An integer vector.

See Also

re2_regexp for options to regular expression, re2_syntax for regular expression syntax.

Examples

color <- c("yellowgreen", "steelblue", "goldenrod", "forestgreen")
re2_count(color, "e")
re2_count(color, "r")

# Regular expression vs literal string
re2_count(c("..", "a...", "foo.b"), ".")
re2_count(c("..", "a...", "foo.b"), re2_regexp(".", literal = TRUE))

re2 documentation built on May 29, 2024, 6:40 a.m.