Text & patterns
Scalar
regexp_replace()
If string contains the regex, replaces the matching part with replacement. A set of optional regex options can be set.
Reference: Haybarn WASM 2.0.0-rc12
Arguments & returns
2 overloadsregexp_replace(string, regex, replacement)
Scalar
| Overload link | string | regex | replacement |
Returns |
|---|---|---|---|---|
| #01 | VARCHAR | VARCHAR | VARCHAR |
VARCHAR |
regexp_replace(string, regex, replacement, options)
Scalar
| Overload link | string | regex | replacement | options |
Returns |
|---|---|---|---|---|---|
| #02 | VARCHAR | VARCHAR | VARCHAR | VARCHAR |
VARCHAR |
Replace text with regular expressions
Clean strings by replacing text that matches a regular expression. Use the g option when every match should be replaced.
A NULL input produces NULL. A string without a match is returned unchanged.
Haybarn WASM 2.0.0-rc12 · In your browser
Guide example · Run to view results.
| first_match | all_matches | missing |
|---|---|---|
A# B34 | A# B# | NULL |
Watch for: Without the g option, only the first match is replaced. Use replace() when the search text is literal rather than a pattern.
Example
Haybarn WASM 2.0.0-rc12 · In your browser
Engine example · Run to view results.
In a query
Turn a label into a useful key.
Trim the edges, normalize case, and replace runs of spaces. Small functions compose into a readable cleaning step.
Haybarn WASM 2.0.0-rc12 · In your browser
Guide recipe · Run to view results.
In other engines
Exasolregexp_replace()
REGEXP_REPLACE(subject, pattern, replacement, position, occurrence)
REGEXP_REPLACE(subject, pattern, replacement)
Snowflakeregexp_replace()
REGEXP_REPLACE(subject, pattern)
REGEXP_REPLACE(subject, pattern, '', 'g')