↑↓ select ↵ open ⌫ change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Functions / String Functions And Operators

regexp_replace

Read the PG 18 manual

Replaces the substring that is the first match to the POSIX regular expression pattern, or all such matches if the g flag is used; see Section 9.7.3.

Reading PG 18current·documented in 22 of 27 versions, 8.1 to 20

Signatures & examples

regexp_replace ( string text, pattern text, replacement text [, flags text ] ) → text
Replaces the substring that is the first match to the POSIX regular expression pattern, or all such matches if the g flag is used; see Section 9.7.3.
regexp_replace('Thomas', '.[mN]a.', 'M') → ThM
regexp_replace ( string text, pattern text, replacement text, start integer [, N integer [, flags text ] ] ) → text
Replaces the substring that is the N'th match to the POSIX regular expression pattern, or all such matches if N is zero, with the search beginning at the start'th character of string. If N is omitted, it defaults to 1. See Section 9.7.3.
regexp_replace('Thomas', '.', 'X', 3, 2) → ThoXas
regexp_replace(string=>'hello world', pattern=>'l', replacement=>'XX', start=>1, "N"=>2) → helXXo world
Version history 6
  1. 18 → 19 changed
  2. 17 → 18 changed
  3. 14 → 15 changed
  4. 12 → 13 changed
  5. 8.2 → 8.3 changed
  6. 8.0 → 8.1 added

Definition snapshot: b7bd9cda · English manual source