regexp_like()

一个确定正则表达式是否出现在字符串中的函数

regexp_like() 是一个系统函数,用于确定 POSIX 正则表达式是否在提供的字符串中匹配。

regexp_like()PostgreSQL 15 中添加。

用法

regexp_like ( string text, pattern text [, flags text ] ) → boolean

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

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

请注意,regexp_like() 提供了与 ~ 运算符相同的功能,或者如果与 "i" 标志一起使用,则与 ~* 运算符相同。

变更历史

示例

regexp_like() 的基本用法示例

postgres=# SELECT regexp_like('foobarboo flooobilooo', 'fo{1,}');
 regexp_like
-------------
 t
(1 row)

这等价于

postgres=# SELECT 'foobarboo flooobilooo' ~ 'fo{1,}';
 ?column?
----------
 t
(1 row)

默认情况下,匹配是区分大小写的

postgres=# SELECT regexp_like('foobarboo flooobilooo', 'Fo{1,}');
 regexp_like
-------------
 f
(1 row)

"i" 标志可以覆盖此行为

postgres=# SELECT regexp_like('foobarboo flooobilooo', 'Fo{1,}', 'i');
 regexp_like
-------------
 t
(1 row)

这等价于

postgres=# SELECT 'foobarboo flooobilooo' ~* 'Fo{1,}';
 ?column?
----------
 t
(1 row)

分类

字符串操作, 系统函数

另请参阅

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

反馈

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