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


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


re2_locate(string, pattern)

re2_locate_all(string, pattern)



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


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.


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.


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 March 29, 2022, 5:05 p.m.