R: Locate the indices of the nth instance of a pattern.

str_locate_nth {strex} | R Documentation

## Locate the indices of the nth instance of a pattern.

### Description

The nth instance of an pattern will cover a series of character indices. These functions tell you which indices those are.

### Usage

    str_locate_nth(string, pattern, n)

    str_locate_first(string, pattern)

    str_locate_last(string, pattern)

### Arguments

`string` | A character vector. These functions are vectorized over this argument.
`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 nth instance of the pattern.

### Details

- `str_locate_first(...)` is just `str_locate_nth(..., n = 1)`.

- `str_locate_last(...)` is just `str_locate_nth(..., n = -1)`.

### Value

A two-column matrix. The ith row of this matrix gives the start and end indices of the nth instance of `pattern` in the ith element of `string`.

### Examples

    str_locate_nth(c("abcdabcxyz", "abcabc"), "abc", 2)

[Package strex version 0.1.3 Index]