polars.internals.series.StringNameSpace.count_match

StringNameSpace.count_match(pattern: str) polars.internals.series.Series

Count all successive non-overlapping regex matches.

Parameters
pattern

A valid regex pattern

Returns
UInt32 array. Contain null if original value is null or regex capture nothing.

Examples

>>> s = pl.Series("foo", ["123 bla 45 asd", "xyz 678 910t"])
>>> # count digits
>>> s.str.count_match(r"\d")
shape: (2,)
Series: 'foo' [u32]
[
    5
    6
]