str_like: Detect a pattern in the same way as 'SQL"s 'LIKE' and 'ILIKE'...

View source: R/detect.R

str_likeR Documentation

Detect a pattern in the same way as SQL's LIKE and ILIKE operators

Description

str_like() and str_like() follow the conventions of the SQL LIKE and ILIKE operators, namely:

  • Must match the entire string.

  • ⁠_⁠ matches a single character (like .).

  • ⁠%⁠ matches any number of characters (like ⁠.*⁠).

  • ⁠\%⁠ and ⁠\_⁠ match literal ⁠%⁠ and ⁠_⁠.

The difference between the two functions is their case-sensitivity: str_like() is case sensitive and str_ilike() is not.

Usage

str_like(string, pattern, ignore_case = deprecated())

str_ilike(string, pattern)

Arguments

string

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

pattern

A character vector containing a SQL "like" pattern. See above for details.

ignore_case

[Deprecated]

Value

A logical vector the same length as string.

Note

Prior to stringr 1.6.0, str_like() was incorrectly case-insensitive.

Examples

fruit <- c("apple", "banana", "pear", "pineapple")
str_like(fruit, "app")
str_like(fruit, "app%")
str_like(fruit, "APP%")
str_like(fruit, "ba_ana")
str_like(fruit, "%apple")

str_ilike(fruit, "app")
str_ilike(fruit, "app%")
str_ilike(fruit, "APP%")
str_ilike(fruit, "ba_ana")
str_ilike(fruit, "%apple")

tidyverse/stringr documentation built on Aug. 23, 2024, 7:03 a.m.