Postgres的正则表达式 [英] Regular Expression for Postgres

查看:194
本文介绍了Postgres的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要从符合此模式的postgres表中提取特定字段:

I want to pull a particular field from a postgres table that conforms to this pattern:

/^Untitled Deal \d+$/

例如:


无标题交易1

Untitled Deal 1

无标题交易2

无标题交易3

我在postgres中查询不起作用:

I have the query in postgres which is not working:

SELECT "name" FROM "deals" WHERE ("name" ILIKE '/^Untitled Deal \\d+$/');

有人可以指出我在做什么错吗?

Can anyone point out what I am doing wrong?

推荐答案

您需要使用〜* 代替 ILIKE ,如果要对POSIX样式的正则表达式进行模式匹配。

You need to use ~* instead of ILIKE, if you want to pattern match against POSIX-style regular expressions.

即:

SELECT "name" FROM "deals" WHERE ("name" ~* E'^Untitled Deal \\d+$');



另请参见:




  • 关于模式匹配的PostgreSQL文档

  • See also:

    • PostgreSQL documentation on pattern matching
    • 这篇关于Postgres的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆