Regular Expression Functions¶
This page documents regular expression functions available in Polars SQL.
Note
Supported coverage is limited to valid patterns accepted by
regexp_replace. Unsupported regular expression functions and
incompatible edge cases are recorded in
Polars SQL Differences.
- regexp_replace(string, pattern, replacement) -> varchar()¶
Replaces every instance of the substring matched by the regular expression
patterninstringwithreplacement.Numbered capturing groups can be referenced in
replacementusing$1,$2, and so on.Verified examples:
SELECT regexp_replace('abc123def456', '[0-9]+', '#'); -- 'abc#def#' SELECT regexp_replace('1a 2b 14m', '([0-9]+)([ab]) ', '3c$2 '); -- '3ca 3cb 14m'