---
title: "Introducing pg_re2, fast, RE2-powered regular expressions in Postgres"
description: "pg_re2 is a Postgres extension that brings RE2-powered regular expression functions and operators to Postgres, designed to address both execution speed and syntax compatibility with ClickHouse. It uses finite-automata-based RE2 rather than Postgres's backtracking POSIX engine, and version 0.4.0 adds the @~ operator plus btree and GIN index support. Benchmarks on an AWS m6g.2xlarge with PostgreSQL 18 report RE2's functions running at 1.8x to 8.6x the speed of native equivalents, while indexed operations are 1.1x to 1.8x faster. With pg_clickhouse, using RE2-backed functions such as re2match() keeps regex behavior consistent between Postgres execution and ClickHouse pushdown, including patterns such as Quake\\b. The extension duplicates ClickHouse's suite for string search, replacement, extraction, and splitting."
---

# Introducing pg\_re2, fast, RE2-powered regular expressions in Postgres

[Clickhouse](https://yomu.fyi/company/clickhouse) · Jul 8, 2026

**Type:** Announcement

## Summary

pg\_re2 is a Postgres extension that brings RE2-powered regular expression functions and operators to Postgres, designed to address both execution speed and syntax compatibility with ClickHouse. It uses finite-automata-based RE2 rather than Postgres's backtracking POSIX engine, and version 0.4.0 adds the @~ operator plus btree and GIN index support. Benchmarks on an AWS m6g.2xlarge with PostgreSQL 18 report RE2's functions running at 1.8x to 8.6x the speed of native equivalents, while indexed operations are 1.1x to 1.8x faster. With pg\_clickhouse, using RE2-backed functions such as re2match() keeps regex behavior consistent between Postgres execution and ClickHouse pushdown, including patterns such as Quake\\b. The extension duplicates ClickHouse's suite for string search, replacement, extraction, and splitting.

## Context

Postgres and ClickHouse use different regular expression engines, creating both performance differences and syntax incompatibilities. In particular, expressions pushed down to ClickHouse can produce different results from the same expressions executed in Postgres, complicating compatibility and validation for queries spanning the two systems.

## Approach / What changed

pg\_re2 adds RE2-backed regular expression functions to Postgres, along with the @~ matching operator and btree and GIN index support. It uses the same RE2 library as ClickHouse and duplicates ClickHouse's functions for string search, replacement, extraction, and splitting, allowing pg\_clickhouse pushdown to use matching behavior in both systems.

## Takeaways

- RE2-backed functions benchmarked at 1.8x to 8.6x the performance of PostgreSQL's native regular expression functions on an AWS m6g.2xlarge running PostgreSQL 18.
- pg\_re2 v0.4.0 supports btree and GIN indexes; its gin\_re2\_ops opclass can index byte-equivalent trigrams across punctuation, including patterns such as error\_code=42\[0-9\].
- The re2match() function uses the same RE2 library as ClickHouse, so a pattern such as Quake\\b returns consistent results in Postgres and after ClickHouse pushdown.

**Tags:** [Performance](https://yomu.fyi/topic/performance), [Postgres](https://yomu.fyi/topic/postgres), [Search](https://yomu.fyi/topic/search)

- Source: [Clickhouse](https://clickhouse.com/blog/introducing-pg_re2-regex-in-postgres)
- Source URL: https://clickhouse.com/blog/introducing-pg_re2-regex-in-postgres
- Ingested by Yomu: 2026-08-29T01:38:06.797Z

[Read original post](https://clickhouse.com/blog/introducing-pg_re2-regex-in-postgres)
