Learn R Programming

stringr (version 0.6.2)

str_locate_all: Locate the position of all occurences of a pattern in a string.

Description

Vectorised over string and pattern, shorter is recycled to same length as longest.

Usage

str_locate_all(string, pattern)

Arguments

string
input vector. This must be an atomic vector, and will be coerced to a character vector
pattern
pattern to look for, as defined by a POSIX regular expression. See the ``Extended Regular Expressions'' section of regex for details. See fixed,

Value

  • list of integer matrices. First column gives start postion of match, and second column gives end position.

Details

If the match is of length 0, (e.g. from a special match like $) end will be one character less than start.

See Also

regexpr which this function wraps

str_extract for a convenient way of extracting matches

str_locate to locate position of first match

Examples

Run this code
fruit <- c("apple", "banana", "pear", "pineapple")
str_locate_all(fruit, "a")
str_locate_all(fruit, "e")
str_locate_all(fruit, c("a", "b", "p", "p"))

Run the code above in your browser using DataLab