Learn R Programming

re2 (version 0.1.3)

re2_count: 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)

Value

An integer vector.

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.

See Also

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

Examples

Run this code
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))

Run the code above in your browser using DataLab