stringr (version 0.3)

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

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

Details

Vectorised over string. pattern should be a single pattern, i.e. a character vector of length one.

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")

Run the code above in your browser using DataCamp Workspace