str_starts: Detect the presence/absence of a match at the start/end

View source: R/detect.R

str_startsR Documentation

Detect the presence/absence of a match at the start/end

Description

str_starts() and str_ends() are special cases of str_detect() that only match at the beginning or end of a string, respectively.

Usage

str_starts(string, pattern, negate = FALSE)

str_ends(string, pattern, negate = FALSE)

Arguments

string

Input vector. Either a character vector, or something coercible to one.

pattern

Pattern with which the string starts or ends.

The default interpretation is a regular expression, as described in stringi::about_search_regex. Control options with regex().

Match a fixed string (i.e. by comparing only bytes), using fixed(). This is fast, but approximate. Generally, for matching human text, you'll want coll() which respects character matching rules for the specified locale.

negate

If TRUE, inverts the resulting boolean vector.

Value

A logical vector.

Examples

fruit <- c("apple", "banana", "pear", "pineapple")
str_starts(fruit, "p")
str_starts(fruit, "p", negate = TRUE)
str_ends(fruit, "e")
str_ends(fruit, "e", negate = TRUE)

stringr documentation built on Nov. 15, 2023, 1:08 a.m.