Search code examples
sqlsql-like

Regex for selecting two types of ID


In a table I have an ID field that may vary e.g.

ID

  • 4.01.03.137
  • 0.000.00.3562

Note that the second level could have two or three digits depending on the type of product. I have tried make a query to split that table in two tables, one containing just data with two digits and another one with the three digits data, but I was unable to succeed using regex.

Any help would be appreciated.


Solution

  • for two digits

    SELECT * FROM TestTable
    WHERE ID LIKE '%.[0-9][0-9].%.%'
    

    for three digits

    SELECT * FROM TestTable
    WHERE ID LIKE '%.[0-9][0-9][0-9].%.%'