REGEXP_REPLACE
This function replaces the occurrences of pattern in a string by replace_string.
Syntax
regexp_replace::=
Usage Notes
- For details and examples for regular expressions, refer to Regular Expressions section.
- If pattern is
NULL,stringis returned. - If
replace_stringis omitted orNULL, the matches ofpatternare deleted in the result. - In
replace_stringyou can use captures by \1, \2, ..., \9 or \g<name> which are defined bypattern. - The optional parameter
positiondefines from which position the search shall begin (starting with 1). - The optional positive number
occurrencedefines which occurrence shall be searched for. - For additional information, see functions REPLACE, REGEXP_INSTR, and REGEXP_SUBSTR, and the predicate [NOT] REGEXP_LIKE.
The
occurrences do not overlap. Therefore, search of the second occurrence begins at the first character after the first
occurrence. In case of 0 all occurrences are replaced (default). In case of a positive integer n, the n-th occurrence
will be replaced.
Example
SELECT REGEXP_REPLACE(
'From: my_mail@yahoo.com',
'(?i)^From: ([a-z0-9._%+-]+)@([a-z0-9.-]+\.[a-z]{2,4}$)',
'Name: \1 - Domain: \2') REGEXP_REPLACE;