polars.Expr.str.count_match#
- Expr.str.count_match(pattern: str) Expr [source]#
Count all successive non-overlapping regex matches.
- Parameters:
- pattern
A regex pattern compatible with the regex crate.
- Returns:
- UInt32 array. Contain null if original value is null or regex capture nothing.
Examples
>>> df = pl.DataFrame({"foo": ["123 bla 45 asd", "xyz 678 910t"]}) >>> df.select( ... [ ... pl.col("foo").str.count_match(r"\d").alias("count_digits"), ... ] ... ) shape: (2, 1) ┌──────────────┐ │ count_digits │ │ --- │ │ u32 │ ╞══════════════╡ │ 5 │ │ 6 │ └──────────────┘