regexp_instr()

返回正则表达式在字符串中出现位置的函数

regexp_instr() 是一个系统函数,用于返回字符串中指定 POSIX 正则表达式出现位置的索引。

regexp_instr()PostgreSQL 15 中添加。

用法

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

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

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

变更历史

示例

regexp_instr() 的基本用法示例,这里确定第一个出现的 "ooo" 的起始位置

postgres=# SELECT regexp_instr('foobarboo flooobilooo', 'o{3,}');
 regexp_instr 
--------------
           13
(1 row)

确定从字符串的第 14 个字符开始,第一个出现的 "ooo" 的起始位置

postgres=# SELECT regexp_instr('foobarboo flooobilooo', 'o{3,}', 14);
 regexp_instr 
--------------
           19
(1 row)

分类

字符串操作, 系统函数

另请参阅

regexp_count(), regexp_like(), regexp_substr(), regexp_match(), regexp_matches(), regexp_replace()

反馈

提交任何关于 "regexp_instr()" 的评论、建议或更正请 在此处 提交。