Learn R Programming

filesstrings (version 1.1.0)

str_nth_instance_indices: Get the indices of the \(n\)th instance of a pattern.

Description

The \(n\)th instance of an pattern will cover a series of character indices. This function tells you which indices those are.

Usage

str_nth_instance_indices(strings, pattern, n)

Arguments

strings

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.

n

Then \(n\) for the \(n\)th instance of the pattern.

Value

A two-column matrix. The \(i\)th row of this matrix gives the start and end indices of the \(n\)th instance of pattarn in the ith element of strings.

Examples

Run this code
# NOT RUN {
str_nth_instance_indices(c("abcdabcxyz", "abcabc"), "abc", 2)

# }

Run the code above in your browser using DataLab