REGEX_REPLACE_ALL

All functions > STRING > REGEX_REPLACE_ALL

Returns the string with all occurrences of a regular expression pattern replaced.

Signatures

Returns: String with all matches replaced

REGEX_REPLACE_ALL(string: VARCHAR, pattern: VARCHAR, replacement: VARCHAR) → VARCHAR
sql
ParameterTypeRequiredDescription
stringVARCHARYesString to search in
patternVARCHARYesRegular expression pattern to match
replacementVARCHARYesReplacement string (supports backreferences like \1)

Notes

  • All non-overlapping matches are replaced
  • Supports backreferences in the replacement string (\1, \2, etc.)
  • If the pattern does not match, returns the original string unchanged
  • Use REGEX_REPLACE_FIRST to replace only the first occurrence

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
;
Result
f1 VARCHARf2 VARCHARf3 VARCHARf4 VARCHAR
abcNUMdefNUMbaz bar baz extra spaces no match

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19