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
| Parameter | Type | Required | Description |
|---|---|---|---|
string | VARCHAR | Yes | String to search in |
pattern | VARCHAR | Yes | Regular expression pattern to match |
replacement | VARCHAR | Yes | Replacement 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_FIRSTfor a single replacement - If the pattern does not match, the original string is returned unchanged
Aliases
REGEXP_REPLACE_ALL
See also
Examples
FeatureQL
SELECT
-- Replace all digit groups
f1 := REGEX_REPLACE_ALL('abc123def456', '[0-9]+', 'NUM'),
-- All occurrences replaced
f2 := REGEX_REPLACE_ALL('foo bar foo', 'foo', 'baz'),
-- Normalize whitespace
f3 := REGEX_REPLACE_ALL(' extra spaces ', '\s+', ' '),
-- No match returns original
f4 := REGEX_REPLACE_ALL('no match', '[0-9]+', 'X'),
-- NULL haystack
f5 := REGEX_REPLACE_ALL(NULL(VARCHAR), 'a', 'b')
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR | f4 VARCHAR | f5 VARCHAR |
|---|---|---|---|---|
| abcNUMdefNUM | baz bar baz | extra spaces | no match | NULL |
On this page