re2_locate: Locate the start and end of pattern in a string

View source: R/RcppExports.R

re2_locateR Documentation

Locate the start and end of pattern in a string

Description

Vectorized over string and pattern. For matches of 0 length (ex. spatial patterns like "$") end will be one character greater than beginning.

Usage

re2_locate(string, pattern)

re2_locate_all(string, pattern)

Arguments

string

A character vector, or an object which can be coerced to one.

pattern

Character string containing a regular expression, or a pre-compiled regular expression (or a vector of character strings and pre-compiled regular expressions).
See re2_regexp for available options.
See re2_syntax for regular expression syntax.

Value

re2_locate returns an integer matrix, and re2_locate_all returns a list of integer matrices.

See Also

re2_regexp for options to regular expression, re2_syntax for regular expression syntax.

Examples

color <- c("yellowgreen", "steelblue", "goldenrod", "forestgreen")

re2_locate(color, "$")
re2_locate(color, "l")
re2_locate(color, "e")

# String length can be a multiple of pattern length
re2_locate(color, c("l(l|d)?", "st"))

# Locate all occurrences
re2_locate_all(color, "l")
re2_locate_all(color, "e")

# Locate all characters
re2_locate_all(color, ".")

re2 documentation built on May 29, 2024, 6:40 a.m.