跳转到主要内容

omni_regex

Omnigres PCRE兼容正则表达式模块

omnigres · Omnigres PCRE兼容正则表达式模块

概览

ID扩展软件包版本类别许可证编程语言
2961omni_regexomnigres0.1.0FEATApache-2.0C
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d-r否是否是是否

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.1.019 18 17 16 15omnigres-
RPMPIGSTY2026021219 18 17 16 15omnigres_$vpostgresql$v-contrib, postgresql$v-plpython3, python3-pip
DEBPIGSTY2026021219 18 17 16 15postgresql-$v-omnigrespostgresql-plpython3-$v, python3-pip
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el8.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el9.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el9.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el10.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el10.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
d12.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
d12.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
d13.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
d13.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u22.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u22.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u24.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u24.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u26.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u26.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212

源码

pig build pkg omnigres;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

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

使用 pig 安装扩展。

pig install omnigres;		# install by package name
pig install omni_regex;		# install by extension name

pig install omni_regex -v 18;   # install for PG 18
pig install omni_regex -v 17;   # install for PG 17
pig install omni_regex -v 16;   # install for PG 16
pig install omni_regex -v 15;   # install for PG 15

在数据库中创建扩展。

CREATE EXTENSION omni_regex;

用法

omni_regex: PCRE 兼容正则表达式

omni_regex 扩展提供基于 PCRE2 的正则表达式支持,包含命名捕获组功能。

运算符

运算符描述
~字符串匹配正则表达式
!~不匹配运算符
=~替代匹配方式(同 ~)
SELECT 'foo' ~ regex 'fo+';   -- true
SELECT 'bar' !~ regex 'foo';  -- true

函数

regex_match(text, regex) – 返回第一个匹配的捕获组:

SELECT regex_match('ABC123', '([A-Z]*)(\d+)');  -- {ABC,123}

regex_matches(text, regex) – 返回所有匹配结果的文本数组集合:

SELECT regex_matches('foo1bar', '(fo+|bar)(\d?)');
-- {foo,1}
-- {bar,""}

regex_named_groups(regex) – 提取命名捕获组:

SELECT index FROM regex_named_groups('(fo+|bar)(?<num>\d?)')
WHERE name = 'num';  -- 2

命名捕获组语法:(?<name>REGEX)

表格阅读器