Follows the structure of the SQL LIKE operator:

  • Must match the entire string

  • _ matches a single character (like .)

  • % matches any number of characters (.*)

  • \% and \_ match literal % and _

  • The match is case insentistive by default

str_like(string, pattern, ignore_case = TRUE)

Arguments

string

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

pattern

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

ignore_case

Ignore case of matches? Defaults to TRUE to match the SQL LIKE operator.

Value

A logical vector.

Examples

fruit <- c("apple", "banana", "pear", "pinapple") str_like(fruit, "app")
#> [1] FALSE FALSE FALSE FALSE
str_like(fruit, "app%")
#> [1] TRUE FALSE FALSE FALSE
str_like(fruit, "ba_ana")
#> [1] FALSE TRUE FALSE FALSE
str_like(fruit, "%APPLE")
#> [1] TRUE FALSE FALSE TRUE