Learn R Programming

re2 (version 0.1.3)

re2_locate: 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)

Value

re2_locate returns an integer matrix, and

re2_locate_all returns a list of integer matrices.

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.

See Also

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

Examples

Run this code
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, ".")

Run the code above in your browser using DataLab