Learn R Programming

filesstrings (version 1.1.0)

count_matches: Count the number of the matches of a pattern in a string.

Description

Vectorised over string and pattern.

Usage

count_matches(string, pattern)

Arguments

string

A character vector.

pattern

A character vector. Pattern(s) specified like the pattern(s) in the stringr package (e.g. look at stringr::str_locate()). If this has length >1 its length must be the same as that of string.

Value

A numeric vector giving the number of matches in each string.

Examples

Run this code
# NOT RUN {
count_matches("abacad", "a")
count_matches("2.1.0.13", ".")
count_matches("2.1.0.13", stringr::coll("."))
# }

Run the code above in your browser using DataLab