MySQL REGEXP for numbers that start with

I need to write a query using MYSQL REGEXP that will find me rows whose specific column starts with 11 or 12 or so on. I know that I can use LIKE or LEFT (####, 2), but I would like to use the REGEXP parameter. My data is stored as 110001, 122122, 130013a, etc.

EDIT 1:

To make this clearer, I would like to express

SELECT * FROM table WHERE column LIKE '11%' or column LIKE '12%' or column LIKE '30%'"     

with REGEXP

Thank!

+5
source share
1 answer

To match strings starting with two digits, you can use:

SELECT *
FROM yourtable
WHERE yourcolumn REGEXP '^[0-9][0-9]';

If you want to allow lines starting with 11, 12or 30, you can use this:

SELECT *
FROM yourtable
WHERE yourcolumn REGEXP '^(11|12|30)';

, , LIKE.

+15

All Articles