Hex characters in regexp matching in mysql
This matches too:
SELECT CONVERT('a' USING BINARY) REGEXP '[1-\x]'
The reason is that \x
is interpeted as x
and a
comes between 1
and x
. The rest of your regex is just ordinary characters that aren't relevant here because they're already inside the [1-x] range.
SELECT CONVERT('0' USING BINARY) REGEXP '[\x61-\x61]' -- Fails, because 0 < 1.
SELECT CONVERT('1' USING BINARY) REGEXP '[\x61-\x61]' -- Succeeds: inside [1-x].
SELECT CONVERT('2' USING BINARY) REGEXP '[\x61-\x61]' -- Succeeds: inside [1-x].
...
SELECT CONVERT('w' USING BINARY) REGEXP '[\x61-\x61]' -- Succeeds: inside [1-x].
SELECT CONVERT('x' USING BINARY) REGEXP '[\x61-\x61]' -- Succeeds: inside [1-x].
SELECT CONVERT('y' USING BINARY) REGEXP '[\x61-\x61]' -- Fails, because y > x.
I'm not sure what you're trying to achieve, but if you want hex characters, you can use the hex function:
SELECT HEX('a')
61
to write a regexp like [\x61-\x65]
in mysql, you can use hex values inside a concat:
SELECT CONVERT('a' USING BINARY) REGEXP CONCAT('[', 0x61, '-', 0x65, ']')
Lol... based on the above you can just use the print characters. That worked for me. I wanted to make it match characters not on a USA keyboard and the following expression works on MySQL 5.1:
[^ -~]
That will do the same thing as
[^\x20-\x7E]