Return Rows that Only Contain Non-Alphanumeric Characters in SQLite

Here’s an example of returning rows that contain only non-alphanumeric characters in SQLite.

Non-alphanumeric characters include punctuation characters like !@#&()–[{}]:;',?/* and symbols like `~$^+=<>“, as well as whitespace characters like the space or tab characters.

Sample Data

We’ll use the following data for our examples:

SELECT c1 FROM t1;

Result:

+----------------------+
| c1                   |
+----------------------+
| Music                |
| Live Music           |
| Café                 |
| Café Del Mar         |
| 100 Cafés            |
| [email protected]    |
| 1 + 1                |
| ()                   |
| !@#&()–[{}]:;',?/*   |
| `~$^+=<>“            |
| $1.50                |
| Player 456           |
| 007                  |
| NULL                 |
|                      |
| é                    |
| É                    |
| é 123                |
| ø                    |
| ø 123                |
+----------------------+

We can use the REGEXP operator with a regular expression to return the rows that contain only non-alphanumeric characters:

SELECT c1 FROM t1
WHERE c1 NOT REGEXP '[A-Za-z0-9]';

Result:

+----------------------+
| c1                   |
+----------------------+
| ()                   |
| !@#&()–[{}]:;',?/*   |
| `~$^+=<>“            |
|                      |
| é                    |
| É                    |
| ø                    |
+----------------------+

In this case, my exclusion range didn’t cover alphanumeric characters like é, É, and ø. The following example expands the range to exclude those characters from the result:

SELECT c1 FROM t1
WHERE c1 NOT REGEXP '[A-Za-zÀ-Þß-ÿ0-9]';

Result:

()                
!@#&()–[{}]:;',?/*
`~$^+=<>“         
                  

Our table also contains a row with the empty string. This is a non-alphanumeric character, and so it’s returned in the above result. We can also use the NULLIF() function to exclude the empty string from the output:

SELECT c1 FROM t1
WHERE NULLIF(c1, '') NOT REGEXP '[A-Za-zÀ-Þß-ÿ0-9]';

Result:

()                
!@#&()–[{}]:;',?/*
`~$^+=<>“