How do I REGEXP search based on hex codes in MYSQL?

mysql, regex

Solution

There may be a better way to do this, but here is what I came up with:

SELECT title FROM tags WHERE title REGEXP CONCAT('[',CHAR(1),'-',CHAR(31),']')

Note that these are decimal character values, not hex. I also couldn't figure out a way to get it to find NULL bytes (`\x00`) as well.

Here is an alternative that uses hex literals:

SELECT title FROM tags WHERE title REGEXP CONCAT('[', x'01', '-', x'1F', ']')

Problem

`SELECT title FROM tags WHERE title REGEXP '[\x20]'` returns all things with x, 2, or 0; `SELECT title FROM tags WHERE title REGEXP '\x20'` returns all things with literally x20 My actual use-case is that I want to search for any tags that may have accidentally gotten control characters in.

Original source