我有一个字符串:我今年10岁,有500个朋友。 我希望返回10和500,但当我执行下面的查询时,它返回了空值:
SELECT
REGEXP_MATCHES('I have the string: I am 10 years old with 500 friends',
'-?\\d+','g');
我有一个字符串:我今年10岁,有500个朋友。 我希望返回10和500,但当我执行下面的查询时,它返回了空值:
SELECT
REGEXP_MATCHES('I have the string: I am 10 years old with 500 friends',
'-?\\d+','g');
select regexp_matches(
'I have the string: I am 10 years old with 500 friends',
'-?\d+',
'g'
);
'-?'
对于您的示例字符串没有意义。我将其保留原样,以防您需要考虑可能存在的负数。"将\\d
替换为[0-9]
:
SELECT
REGEXP_MATCHES(
'I have the string: I am 10 years old with 500 friends',
'(-?[0-9]+)','g'
)
输出:
10
500
请查看实时演示。