I have the string: I am 10 years old with 500 friends. I want to return 10 and 500 but when I executed the query below and it returned empty:
SELECT
REGEXP_MATCHES('I have the string: I am 10 years old with 500 friends',
'-?\\d+','g');
The problem is with the double anti-slash. While some databases require regex character classes to be escaped, Postgres expects just one anti-slash.
So:
select regexp_matches(
'I have the string: I am 10 years old with 500 friends',
'-?\d+',
'g'
);
'-?' is not sensible for your example string. I left it as is in case you want to accomodate for possible negative numbers.
Demo on DB Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With