Search code examples
mysqlstringcontrol-characters

Find control characters in MySQL


What is the best way to find control characters within a string in MySQL? I have a table and want to get all records, that contain control characters. Something like

SELECT * FROM Customer WHERE Name = *ControlCharFilter*;

in C# it would be

Customer.Where(x => x.Name.Any(y => char.IsControl(y));

Solution

  • MySQL supports regular expressions with POSIX character classes:

    SELECT * FROM Customer WHERE Name RLIKE '[[:cntrl:]]+'
    

    There's more information here.