polars.Expr.str.escape_regex#
- Expr.str.escape_regex() Expr [source]#
Returns string values with all regular expression meta characters escaped.
Examples
>>> df = pl.DataFrame({"text": ["abc", "def", None, "abc(\\w+)"]}) >>> df.with_columns(pl.col("text").str.escape_regex().alias("escaped")) shape: (4, 2) ┌──────────┬──────────────┐ │ text ┆ escaped │ │ --- ┆ --- │ │ str ┆ str │ ╞══════════╪══════════════╡ │ abc ┆ abc │ │ def ┆ def │ │ null ┆ null │ │ abc(\w+) ┆ abc\(\\w\+\) │ └──────────┴──────────────┘