regexp_match() 是一个系统函数,用于返回与 POSIX 正则表达式匹配的第一个子字符串。
regexp_match() 已在 PostgreSQL 10 中添加。
用法
regexp_match (stringtext,patterntext[,flagstext] ) →text[]
命名参数从 PostgreSQL 18 开始可用。
regexp_match() 本质上是 regexp_matches() 的简化版本。可以在 PostgreSQL 文档中找到与 regexp_match() 一起使用的标志列表:ARE 嵌入式选项字母。
变更历史
- PostgreSQL 18
- 添加了对参数名称的支持(提交 580f8727)
- PostgreSQL 10
- 添加(提交 cf9b0fea)
示例
regexp_match() 的基本用法示例
postgres=# SELECT regexp_match('foobarboo', '.oo');
regexp_match
--------------
{foo}
(1 row)
'g' 标志不能与 regexp_match() 一起使用
postgres=# SELECT regexp_match('foobarboo', '.oo', 'g');
ERROR: regexp_match does not support the global option
HINT: Use the regexp_matches function instead.
参考资料
- PostgreSQL 文档: 其他字符串函数
