Skip to content

Use the Aho-Corasick algorithm to find matches

Source code

Description

This function determines if any of the patterns find a match.

Usage

<Expr>$str$contains_any(patterns, ..., ascii_case_insensitive = FALSE)

Arguments

patterns String patterns to search. Accepts expression input. To use the same character vector for all rows, use list(c(…)) instead of c(…) (see Examples).
These dots are for future extensions and must be empty.
ascii_case_insensitive Enable ASCII-aware case insensitive matching. When this option is enabled, searching will be performed without respect to case for ASCII letters (a-z and A-Z) only.

Value

A polars expression

See Also

  • \$str$contains()

Examples

library("polars")

df <- pl$DataFrame(
  lyrics = c(
    "Everybody wants to rule the world",
    "Tell me what you want, what you really really want",
    "Can you feel the love tonight"
  )
)

df$with_columns(
  contains_any = pl$col("lyrics")$str$contains_any(list(c("you", "me")))
)
#> shape: (3, 2)
#> ┌─────────────────────────────────┬──────────────┐
#> │ lyrics                          ┆ contains_any │
#> │ ---                             ┆ ---          │
#> │ str                             ┆ bool         │
#> ╞═════════════════════════════════╪══════════════╡
#> │ Everybody wants to rule the wo… ┆ false        │
#> │ Tell me what you want, what yo… ┆ true         │
#> │ Can you feel the love tonight   ┆ true         │
#> └─────────────────────────────────┴──────────────┘