polars.Series.str.extract_all#

Series.str.extract_all(pattern: str | Series) Series[source]#

Extracts all matches for the given regex pattern.

Extract each successive non-overlapping regex match in an individual string as an array

Parameters:
pattern

A valid regex pattern

Returns:
List[Utf8] array. Contain null if original value is null or regex capture
nothing.

Examples

>>> s = pl.Series("foo", ["123 bla 45 asd", "xyz 678 910t"])
>>> s.str.extract_all(r"(\d+)")
shape: (2,)
Series: 'foo' [list[str]]
[
    ["123", "45"]
    ["678", "910"]
]