Check if string starts with a regex
Description
Check if string values starts with a substring.
Usage
<Expr>$str$starts_with(sub)
Arguments
sub
|
Prefix substring or Expr. |
Details
See also $str$contains()
and
$str$ends_with()
.
Value
Expr of Boolean data type
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 │
#> └────────┴────────────┘