Skip to content

Check if string starts with a regex

Description

Check if string values starts with a substring.

Usage

<Expr>$str$starts_with(prefix)

Arguments

prefix Prefix substring or Expr.

Details

See also $str$contains() and $str$ends_with().

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(fruits = c("apple", "mango", NA))
df$select(
  pl$col("fruits"),
  pl$col("fruits")$str$starts_with("app")$alias("has_suffix")
)
#> shape: (3, 2)
#> ┌────────┬────────────┐
#> │ fruits ┆ has_suffix │
#> │ ---    ┆ ---        │
#> │ str    ┆ bool       │
#> ╞════════╪════════════╡
#> │ apple  ┆ true       │
#> │ mango  ┆ false      │
#> │ null   ┆ null       │
#> └────────┴────────────┘