I am trying to extract decimal numbers from a random string. How to do this using regex_replace function? Optionally i want to retain negative sign for negative integers.
example:
input:
'text abc023.46'
'-123.12abc'
output:
023.46
-123.12
I am trying to extract decimal numbers from a random string. How to do this using regex_replace function? Optionally i want to retain negative sign for negative integers.
example:
input:
'text abc023.46'
'-123.12abc'
output:
023.46
-123.12
Use REGEXP_SUBSTR
:
SELECT REGEXP_SUBSTR(col, '-?\d+(\.\d+)?')
FROM yourTable;
This pattern also makes the decimal component optional.