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
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 VARCHAR | f2 VARCHAR | f3 VARCHAR | f4 VARCHAR | f5 VARCHAR |
|---|---|---|---|---|
| abcNUMdefNUM | baz bar baz | extra spaces | no match | NULL |
On this page