regexp_replace function

Replaces all substrings of str that match regexp with rep.

Syntax

regexp_replace(str, regexp, rep [, position] )

Arguments

  • str: A STRING expression to be matched.

  • regexp: A STRING expression with a matching pattern.

  • rep: A STRING expression which is the replacement string.

  • position: A optional integral numeric literal greater than 0, stating where to start matching. The default is 1.

Returns

A STRING.

The regexp string must be a Java regular expression. String literals are unescaped. For example, to match '\abc', a regular expression for regexp can be '^\\abc$'. Searching starts at position. The default is 1, which marks the beginning of str. If position exceeds the character length of str, the result is str.

Examples

> SELECT regexp_replace('100-200', '(\\d+)', 'num');
 num-num