Home > Software design >  EXTRACT number using regex in SQL
EXTRACT number using regex in SQL

Time:09-29

I have data like this

/product/12345

and I want to extract the number after the second "/". Does anyone know how to do that?

Thank you

CodePudding user response:

You can use \d to match the digit

/\d*/g

CodePudding user response:

Not knowing what RDBMS you are using below is something that works with PostgreSQL:

SELECT SUBSTRING (
               '/product/12345'
               FROM
               '%/%/#"%#"%' FOR '#'
           )::numeric;

CodePudding user response:

Id use something like

Select * From Table Where (column REGEXP '(?:\/product\/)\K\d ' )

If you want the output to be the number follow this

regex explanation
regex in sql explanation

  • Related