REGEX_REPLACE_ALL()

All functions > STRING > REGEX_REPLACE_ALL()

Returns the haystack with every non-overlapping regular-expression match replaced by the replacement string.

Signatures

Returns: Updated string; unchanged if there is no match; NULL if the haystack is NULL

REGEX_REPLACE_ALL(string: VARCHAR, pattern: VARCHAR, replacement: VARCHAR) → VARCHAR
sql
ParameterTypeRequiredDescription
stringVARCHARYesString to search in
patternVARCHARYesRegular expression pattern to match
replacementVARCHARYesReplacement text; capture-group backreferences (a backslash followed by the group number) are supported where the underlying regex implementation allows

Notes

  • All non-overlapping matches are replaced; use REGEX_REPLACE_FIRST for a single replacement
  • If the pattern does not match, the original string is returned unchanged

See also

Examples

FeatureQL
SELECT
    f1 := REGEX_REPLACE_ALL('abc123def456', '[0-9]+', 'NUM'), -- Replace all digit groups
    f2 := REGEX_REPLACE_ALL('foo bar foo', 'foo', 'baz'), -- All occurrences replaced
    f3 := REGEX_REPLACE_ALL('  extra   spaces  ', '\s+', ' '), -- Normalize whitespace
    f4 := REGEX_REPLACE_ALL('no match', '[0-9]+', 'X'), -- No match returns original
    f5 := REGEX_REPLACE_ALL(NULL(VARCHAR), 'a', 'b') -- NULL haystack
;
Result
f1 VARCHARf2 VARCHARf3 VARCHARf4 VARCHARf5 VARCHAR
abcNUMdefNUMbaz bar baz extra spaces no matchNULL

Last update at: 2026/05/26 17:22:09