Sign up ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have the following situation. I have to substring regular expression from description using MySQL. Description:

Lorem D9801 ipsum dolor sit amet

Where D9801 is REGEXP. Every strong text description has different content but my regexp should looks like: REGEXP 'D[[:digit:]]{4}'

REGEXP always has "D" at the beginning and "xxxx" - 4 digits at the end: Dxxxx

I know the REGEXP returns only true/false value, but how can I make query to return only 'D9801' value?

I tried something like this:

SELECT SUBSTRING (description, LOCATE(REGEXP 'D[[:digit:]]{4}', description), 5)
   SELECT "Lorem D9801 ipsum dolor sit amet" AS description
) temp

I know it's wrong, so I try with this:

    SUM(description REGEXP 'D[[:digit:]]{4}') AS matches, 
        WHEN (SUM(description REGEXP 'D[[:digit:]]{4}') > 0) THEN 
            SUBSTRING(description, LOCATE( /*POSITION_OF_REGEXP_IN_DESC*/ , description), 5)
        ELSE 'Brak schematu'
    END AS show_substr FROM ps_description GROUP BY id;

But how to find position of regexp?

I heard about UDF but I cannot use it, I use OVH hosting.

share|improve this question
This is basically a dup of:… –  Nathan Feger Aug 14 at 17:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.