PostgreSQL反向模式匹配(字段模式)

Fen*_*der 0 regex postgresql

我有一张这样的桌子:

id: 1
pattern: /test.*

id: 2
pattern: /hello-world
Run Code Online (Sandbox Code Playgroud)

和这个输入值: /test-request

现在我想为给定的输入创建一个查询,postgres应返回行,其中第二列的模式与输入匹配(正则表达式搜索,但正则表达式在搜索字段中)

这可能与postgres数据库有关吗?

a_h*_*ame 6

您可以为正则表达式运算符使用列值:

select id, pattern 
from patterns
where '/test-request' ~* pattern;
Run Code Online (Sandbox Code Playgroud)

~*不区分大小写的匹配,~区分大小写匹配.

SQLFiddle示例:http://sqlfiddle.com/#!15/388a4/2