str_starts: Detect the presence or absence of a pattern at the beginning...

View source: R/detect.R

str_startsR Documentation

Detect the presence or absence of a pattern at the beginning or end of a string.

Description

Vectorised over string and pattern, though using vectorised patterns is relatively slow compared to stringr.

Usage

str_starts(string, pattern, negate = FALSE)

str_ends(string, pattern, negate = FALSE)

Arguments

string

character vector of strings.

pattern

character, a pattern with which the string should start or end.

Can be:

  • A Perl-compatible regular expression (default).

  • Wrap with perl(ignore_case = TRUE) to use case-insensitive matching.

  • Wrap with fixed() to use a fixed/literal match.

  • Wrap with regex() to use a POSIX 1003.2 extended regular expression.

  • Wrap with regex(ignore_case = TRUE) to use case-insensitive matching with a POSIX 1003.2 extended regular expression.

negate

logical, if TRUE return non-matching elements. Default is FALSE.

Value

Returns a logical vector the same length as string.

See Also

str_detect() which this function wraps.

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)


csdaw/stringrb documentation built on Aug. 13, 2022, 10:55 p.m.