How to extract only numbers from string in mysql?

by haylee.mertz , in category: MySQL , a year ago

How to extract only numbers from string in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by darrion.kuhn , a year ago

@haylee.mertz 

You can use the REGEXP function in MySQL to extract only numbers from a string. Here's an example query:


SELECT REGEXP_REPLACE('abc123def456', '[^0-9]+', '') AS numbers;


In this query, the REGEXP_REPLACE function is used to replace all non-numeric characters (represented by [^0-9]+) with an empty string. The result will be a string that contains only the numbers from the original input string.


The above example will output "123456" as it extracts only the numbers from the input string "abc123def456".

Related Threads:

How to extract specific part from a string in mysql?
How to extract numbers in bracket with regex?
How to dynamically extract numbers before text with regex?
How to format numbers in mysql?
How to find and extract date in string with php?
How to extract part of string using regex?