Appearance
REGEXP_REPLACE
Replace instances of a pattern in the input with the value in the replacement.
Back references can be used within the replacement string to match expressions within capturing groups. Capturing groups can range from 1 to 9 (\1 to \9).
The entire match can be retrieved with \&.
Syntax
result = REGEXP_REPLACE(input, pattern, replacement [, start [, reference]] [, flags])- input value
Specify the value against which the regular expression is matched.
- pattern value
Specify the regular expression to be matched against the
input.When the
patternmatches, the matched string from theinputwill be replaced by the value specified in thereplacementargument.The
patternvalue must be a constant string and cannot be a column reference.- replacement value
Specify the value to substitute for each instance of the
pattern.- start value
The position in the
inputfrom where thepatternmatch starts. The default start position is 1.Yellowbrick does not support special meanings for negative
startvalues.The
startvalues can be column references.- reference value
Specify which match of the
patternto replace.To replace a specific instance of the
pattern, use areferencevalue greater than 0 to indicate the occurrence. For example, areferencevalue of 1 would replace the first match of thepattern, areferencevalue of 2 would replace the second match of thepattern, and so on.To replace all occurrences, omit a
referencevalue or use areferencevalue of 0, both of which are interpreted similarly and result in a global replace.The
referencevalues can be column references.- flags value
Can be either
ifor case-insensitive orcfor case-sensitive matching. Matching is case-sensitive by default.The
flagsvalue must be a constant string and cannot be a column reference.
Return
If the pattern matches the input, the function applies the replacement and returns the result.
If the pattern doesn't match the input, the function returns the input string.
Example
premdb=> select season_name,REGEXP_REPLACE(season_name,'(\d{4,4})','year:\1', 1, 1) from season where numteams=22;
season_name | regexp_replace
-------------+----------------
1992-1993 | year:1992-1993
1993-1994 | year:1993-1994
1994-1995 | year:1994-1995
(3 rows)