I need to extract an customer number of 5 to 6 digits long from a comment column from a mysql table.
I found documentation to use WHERE REGEXP()
for filtering some results with a regular expression but nothing to extract a part of a sentence in SELECT
statement.
What I would is something like this :
SELECT SUBSTRING(`commment`, REGEXP('^[0-9]{5,6}$')) as `customer_number`
Example of content :
id | firstname | lastname | comment
---------------------------------------------------------------------
1 | John | Doe | Abo 674202 du 01.06.17-31.05.18/emu.
2 | Jane | Doe | Abo. 96735 mis en service le 23.05.17/emu
I need to extract 674202
, 96735
, ...