Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Postgres中的正则表达式_Regex_Postgresql_Sequence_Numeric - Fatal编程技术网

Regex Postgres中的正则表达式

Regex Postgres中的正则表达式,regex,postgresql,sequence,numeric,Regex,Postgresql,Sequence,Numeric,全部 我正在查询Postgres 9.3数据库,查找字段中的特定模式: SELECT P.id, P.processo_id, PR.num_formated FROM publications P INNER JOIN processos PR ON PR.id=P.processo_id WHERE --The first numeric sequence must be exact 4 digits length, so the initial \d{4} PR.num_forma

全部

我正在查询Postgres 9.3数据库,查找字段中的特定模式:

SELECT
 P.id, P.processo_id, PR.num_formated
FROM
 publications P
INNER JOIN processos PR ON PR.id=P.processo_id
WHERE
 --The first numeric sequence must be exact 4 digits length, so the initial \d{4}
 PR.num_formated ~ '\d{4}[\.\-\\]\d{2}\.\d{4}\.\d{1}\.\d{2}\.\d{4}'
AND
 P.id=781291700 --Just to force a specific record
其中PR.num_formatted定义为字符varying255。执行后,查询返回:

  P.id      P.processo_id        PR.num_formated
781291700     502707245    20190001418-14.1998.8.05.0103
我的问题是:为什么Postgres会忽略第一个\d?它解释正则表达式的形式是否有任何特殊性,不同于传统/正则/正统/任何方式,因为同一个正则表达式在我的系统的另一部分可以完美地工作,但使用的是ruby代码

提前谢谢


Walid将忽略前7个字符,因为查询将模式作为字符串的一部分查找。如果要匹配整个字符串,请使用^and$


预期产量是多少?结果似乎与您给出的正则表达式相匹配。您应该以一种不需要我们访问您的计算机即可进行测试的方式编写示例。选择'20190001418-14.1998.8.05.0103'~'\d{4}[\.\-\]\d{2}\.\d{4}\.\d{1}.\d{2}.\d{4}';此正则表达式在ruby中的行为与在postgresql中的行为相同。我找到了ruby-le'print 20190001418-14.1998.8.05.0103=~/\d{4}[\.\-\]\d{2}.\d{4}.\d{1}.\d{2}.\d{4}/'你说得对,伙计。我不相信我错过了这些基本的东西。真是个新手犯的错误!谢谢你的耐心。这个错误很常见,可以解释,因为人们更多地使用LIKE操作符,它以不同的方式处理问题。
'^\d{4}[\.\-\\]\d{2}\.\d{4}\.\d{1}\.\d{2}\.\d{4}$'