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

count_matches {filesstrings} | R Documentation

## Count the number of the matches of a pattern in a string.

### Description

Vectorized 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

An integer vector giving the number of matches in each string.

### Examples

    count_matches(c("abacad", "xyz"), "a")
    count_matches("2.1.0.13", ".")
    count_matches("2.1.0.13", stringr::coll("."))

[Package filesstrings version 2.5.0 Index]