stringr (version 0.5)

str_locate: Locate the position of the first occurence of a pattern in a string.

Description

Locate the position of the first occurence of a pattern in a string.

Usage

str_locate(string, pattern)

Arguments

string
input character vector
pattern
pattern to look for. See regex for description.

Value

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

Details

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

See Also

regexpr which this function wraps

str_extract for a convenient way of extracting matches str_locate_all to locate position of all matches

Examples

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

Run the code above in your browser using DataCamp Workspace