Sqlite sorting using regex

I have rows in an sqlite db text field (codes) with values like:

```
M1 
M2/4527
M101
1
2/5
3/1003
101
102

```

I wish to sort codes with all the rows that start with a number first followed by all the codes that start with a letter A through Z.

This is the nearest I've got

```
rawdata = database.rawQuery("SELECT * FROM tablename ORDER BY CASE WHEN " + codes + " GLOB '*^[0-9]*' THEN CAST(" + codes + " AS INTEGER) ELSE CAST(" + codes + " AS TEXT) END, " + codes + " COLLATE NOCASE ASC", null);

```

Which gives me this: 

```
1
101
102
2/5
3/1003
M1
M101
M2/4527

```

The sort order I'm trying to achieve is:

```
1
2/5
3/1003
101
102
M1
M2/4527
M101

```

The codes that contain a slash can, if easier, have the slash and characters after ignored, as long as the character preceding the slash are sorted as per my requirement. So 2/5 would be 2 and 3/1003 would be 3.