Scalar. Returns a given string with the first occurrence of a match for a POSIX regular expression pattern replaced with a second, specified string.
regexp_replace ( string, regex, replacement )
string | A string. |
regex | A POSIX regular expression pattern. This pattern is limited to the Perl syntax. |
replacement | A string to replace the part of the string that matches regex. |
Returns a given string with the first occurrence of a match for a POSIX regular expression pattern replaced with a second, specified string. If string does not contain a match for the POSIX regular expression, the function returns the string with no replacements. If regex is not a valid regular expression, the function returns NULL.
The function works with UTF-8 strings if the -U server option is specified.
regexp_replace('aaadogaaa', '[b-z]*', 'cat') returns 'aaacataaa'.
regexp_replace('aaadogaaa', '[b-z]*', '') returns 'aaaaaa'.
regexp_replace('aaa', '[a-z]*', 'dog') returns 'dog'.
regexp_replace('aaa', '[b-z]*', 'dog') returns 'aaa'.