str_locate: Locate patterns within a string

View source: R/locate.R

str_locateR Documentation

Locate patterns within a string

Description

Locate patterns within a string

Usage

str_locate(string, pattern)

str_locate_all(string, pattern)

Arguments

string

Character vector of strings.

pattern

A pattern to match. Can be:

  • A single string or regex(), to use POSIX 1003.2 extended regular expression.

  • fixed() to use a fixed/literal matchi.

  • perl() to use a Perl-compatible regular expression.

Unlike stringr, pattern must be length 1; it will not be recycled to the same length as string.

Value

For str_locate(), an integer matrix with one row for each element of string, and two columns ("start" and "end"). If the match is of length 0, end will be one character less than start.

For str_locate_all(), a list with one element for each element of string. Each list element is integer matrix with one row for each matche, and two columns ("start" and "end").


hadley/stringb documentation built on Sept. 16, 2023, 9:11 p.m.