pgpcre

Perl Compatible Regular Expression functions

Overview

PackageVersionCategoryLicenseLanguage
pgpcre0.20190509UTILPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
4230pgpcreNoYesNoYesNoYes-
Relatedicu_ext fuzzystrmatch pg_trgm gzip bzip zstd http pg_net

Version

TypeRepoVersionPG VerPackageDeps
EXTMIXED0.201905091817161514pgpcre-
RPMPIGSTY0.201905091817161514pgpcre_$v-
DEBPGDG0.201905091817161514postgresql-$v-pgpcre-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
PGDG 0.20190509
PGDG 0.20190509
PGDG 0.20190509
PGDG 0.20190509
PGDG 0.20190509
d13.x86_64
d13.aarch64
PGDG 0.20190509
PGDG 0.20190509
PGDG 0.20190509
PGDG 0.20190509
PGDG 0.20190509
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64

Build

You can build the RPM packages for pgpcre using pig build:

pig build pkg pgpcre         # build RPM packages

Install

You can install pgpcre directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pgpcre;          # Install for current active PG version
pig ext install -y pgpcre -v 18  # PG 18
pig ext install -y pgpcre -v 17  # PG 17
pig ext install -y pgpcre -v 16  # PG 16
pig ext install -y pgpcre -v 15  # PG 15
pig ext install -y pgpcre -v 14  # PG 14
dnf install -y pgpcre_18       # PG 18
dnf install -y pgpcre_17       # PG 17
dnf install -y pgpcre_16       # PG 16
dnf install -y pgpcre_15       # PG 15
dnf install -y pgpcre_14       # PG 14
apt install -y postgresql-18-pgpcre   # PG 18
apt install -y postgresql-17-pgpcre   # PG 17
apt install -y postgresql-16-pgpcre   # PG 16
apt install -y postgresql-15-pgpcre   # PG 15
apt install -y postgresql-14-pgpcre   # PG 14

Create Extension:

CREATE EXTENSION pgpcre;

Usage

pgpcre: Perl-compatible regular expressions (PCRE) for PostgreSQL

Provides a pcre data type and operators/functions for PCRE pattern matching.

Basic Matching

SELECT 'foo' ~ pcre 'fo+';        -- true
SELECT 'bar' !~ pcre 'fo+';       -- true
SELECT 'foo' =~ pcre 'fo+';       -- true (Perl-style operator)

Reverse operand order:

SELECT pcre 'fo+' ~ 'foo';        -- true
SELECT pcre 'fo+' ~ ANY(ARRAY['foo', 'bar']);

Case-Insensitive Matching

SELECT 'FOO' ~ pcre '(?i)fo+';    -- true

Extract Matched String

SELECT pcre_match('fo+', 'foobar');    -- 'foo'
SELECT pcre_match('fo+', 'barbar');    -- NULL

Extract Captured Substrings

SELECT pcre_captured_substrings('(fo+)(b..)', 'foobar');
-- ARRAY['foo','bar']

SELECT pcre_captured_substrings('(a|(z))(bc)', 'abc');
-- ARRAY['a',NULL,'bc']

Storing Regular Expressions

The pcre type can be stored in table columns. The binary form contains the compiled regex, tied to the PCRE library version. After a PCRE library upgrade, recompile stored values:

UPDATE my_table SET pcre_col = pcre_col::text::pcre;

Last Modified 2026-03-12: add pg extension catalog (95749bf)