polars.internals.expr.ExprStringNameSpace.replace

ExprStringNameSpace.replace(pattern: str, value: str) polars.internals.expr.Expr

Replace first regex match with a string value.

Parameters
pattern

Regex pattern.

value

Replacement string.

Examples

>>> df = pl.DataFrame({"id": [1, 2], "text": ["123abc", "abc456"]})
>>> df.with_column(pl.col("text").str.replace(r"abc", "ABC"))
shape: (2, 2)
┌─────┬────────┐
│ id  ┆ text   │
│ --- ┆ ---    │
│ i64 ┆ str    │
╞═════╪════════╡
│ 1   ┆ 123ABC │
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2   ┆ abc456 │
└─────┴────────┘