polars.Series.str.replace_all#

Series.str.replace_all(pattern: str, value: str, *, literal: bool = False) Series[source]#

Replace all matching regex/literal substrings with a new string value.

Parameters:
pattern

A valid regular expression pattern, compatible with the regex crate.

value

String that will replace the matches.

literal

Treat pattern as a literal string.

See also

replace

Replace first matching regex/literal substring.

Examples

>>> df = pl.Series(["abcabc", "123a123"])
>>> df.str.replace_all("a", "-")
shape: (2,)
Series: '' [str]
[
    "-bc-bc"
    "123-123"
]