str_locate {stringr}R Documentation

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

Description

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

Usage

  str_locate(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, ignore.case and perl for how to use other types of matching: fixed, case insensitive and perl-compatible.

Value

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

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

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

[Package stringr version 0.6.2 Index]