Skip to content

Extract all matches for the given regex pattern

Source code

Description

Extracts all matches for the given regex pattern. Extracts each successive non-overlapping regex match in an individual string as an array.

Usage

<Expr>$str$extract_all(pattern)

Arguments

pattern A valid regex pattern

Value

List[String] array. Contain null if original value is null or regex capture nothing.

Examples

library("polars")

df = pl$DataFrame(foo = c("123 bla 45 asd", "xyz 678 910t"))
df$select(
  pl$col("foo")$str$extract_all(r"((\d+))")$alias("extracted_nrs")
)
#> shape: (2, 1)
#> ┌────────────────┐
#> │ extracted_nrs  │
#> │ ---            │
#> │ list[str]      │
#> ╞════════════════╡
#> │ ["123", "45"]  │
#> │ ["678", "910"] │
#> └────────────────┘