regexp_matches()

返回正则表达式匹配项的函数

regexp_matches() 是一个系统函数,用于返回与 POSIX 正则表达式匹配的子字符串。

regexp_matches()PostgreSQL 8.3 中添加。

用法

regexp_matches ( string text, pattern text [, flags text ] ) → setof text[]

命名参数从 PostgreSQL 18 开始可用。

通常,提供至少一个标志是有意义的,特别是 'g' 标志,否则 regexp_matches() 的行为将与 regexp_match() 完全相同。

除了 'g' 之外的其他标志列表可在 PostgreSQL 文档中找到:ARE 嵌入式选项字母

变更历史

示例

regexp_matches() 的基本用法示例

postgres=# SELECT regexp_matches('foobarboo', '.oo', 'g');
 regexp_matches 
----------------
 {foo}
 {boo}
(2 rows)

检索多个匹配项

postgres=# SELECT regexp_matches('foobarboo floobiloo', '(.oo).+?(.oo)', 'g');
 regexp_matches 
----------------
 {foo,boo}
 {loo,loo}
(2 rows)

请注意,不带 'g' 标志使用 regexp_matches() 等同于 regexp_match()

postgres=# SELECT regexp_match('foobarboo', '.oo'), regexp_matches('foobarboo', '.oo');
 regexp_match | regexp_matches 
--------------+----------------
 {foo}        | {foo}
(1 row)

分类

字符串操作, 系统函数

另请参阅

regexp_match(), regexp_substr()

反馈

提交任何关于 "regexp_matches()" 的评论、建议或更正请点击 此处