我有字符串:我 10 岁,有 500 个 friend 。 我想返回 10 和 500,但是当我执行下面的查询时它返回空值:
SELECT
REGEXP_MATCHES('I have the string: I am 10 years old with 500 friends',
'-?\\d+','g');
最佳答案
问题出在双反斜杠上。虽然一些数据库需要对正则表达式字符类进行转义,但 Postgres 只需要一个反斜杠。
所以:
select regexp_matches(
'I have the string: I am 10 years old with 500 friends',
'-?\d+',
'g'
);
'-?'
对您的示例字符串不敏感。我将其保留原样,以防您想容纳可能的负数。
关于sql - 返回字符串 :postgresql 中的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62614975/