polars.Series.str.replace#
- Series.str.replace(pattern: str, value: str, literal: bool = False, *, n: int = 1) Series [source]#
Replace first matching regex/literal substring with a new string value.
- Parameters:
- pattern
A valid regex pattern.
- value
Substring to replace.
- literal
Treat pattern as a literal string.
- n
Number of matches to replace
See also
replace_all
Replace all matching regex/literal substrings.
Examples
>>> s = pl.Series(["123abc", "abc456"]) >>> s.str.replace(r"abc\b", "ABC") shape: (2,) Series: '' [str] [ "123ABC" "abc456" ]