regexp_substr()

返回匹配正则表达式的子字符串的函数

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

regexp_substr()PostgreSQL 15 中添加。

用法

regexp_substr ( string text, pattern text [, start integer [, N integer [, flags text [, subexpr integer ] ] ] ] ) 
        → text

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

可以在 PostgreSQL 文档中找到与 regexp_substr() 一起使用的标志列表:ARE 嵌入式选项字母

变更历史

示例

regexp_substr() 的基本用法示例,匹配指定正则表达式的第一次出现

postgres=# SELECT regexp_substr('foobarboo flooobilooo', '\wlo{1,}');
 regexp_substr
---------------
 flooo
(1 row)

匹配指定正则表达式的第二次出现

postgres=# SELECT regexp_substr('foobarboo flooobilooo', '\wlo{1,}', 1, 2);
 regexp_substr
---------------
 ilooo
(1 row)

分类

字符串操作, 系统函数

另请参阅

regexp_count(), regexp_instr(), regexp_like(), regexp_match(), regexp_matches(), regexp_replace(), substring()

反馈

提交有关“regexp_substr()”的任何评论、建议或更正,请在此处进行。