REGEX_REPLACE
Description
REGEX_REPLACE
is a row function that evaluates a TEXT
value against a regular expression to determine if there is a match, and replaces matched strings with the specified replacement value.Syntax
REGEX_REPLACE
(string_expression
,"regex_match_pattern
","regex_replace_pattern
")Return Value
Returns the
as a
produces a match. If there is no match, returns the value of
as a
regex_replace_pattern
TEXT
value when regex_match_pattern
string_expression
TEXT
. Input Parameters
- string_expression
- Required. The name of a field or expression of typeTEXT(or a literal string).
- regex_match_pattern
- Required. A string literal or regular expression pattern based on the regular expression pattern matching syntax of the Java programming language. You can use capturing groups to create backreferences that can be used in the. You might want to use a string literal to make a case-sensitive match. For example, when you enterregex_replace_patternjaneas the match value, the function matchesjanebut notJane. The function matches all occurrences of a string literal in the string expression.
- regex_replace_pattern
- Required. A string literal or regular expression pattern based on the regular expression pattern matching syntax of the Java programming language. You can refer to backreferences from theusing the syntaxregex_match_pattern$(wherenis the group number).n
Regular Expression Constructs
See the Regular Expression Reference for information on the constructs used for defining a regular expression matching pattern.
Examples
Match the values in a
phone_number
field where phone number values are formatted as xxx.xxx.xxxx
and replace them with phone number values formatted as (xxx) xxx-xxxx
:REGEX_REPLACE([phone_number], "([0-9]{3})\.([[0-9]]{3})\.([[0-9]]{4})", "\($1\) $2-$3")
Match the values in a
name
field where name values are formatted as firstname lastname
and replace them with name values formatted as lastname, firstname
:REGEX_REPLACE([name], "(.*) (.*)", "$2, $1")
Match the string literal
mrs
in a title
field and replace it with the string literal Mrs
.REGEX_REPLACE([title], "mrs", "Mrs")