John said:
How can I use regular expression to detect all the unprintable characters?
What's an unprintable character?
This is not meant as a brush-off, but you'll have to be a little more
precise, since there are lots of characters that won't print with some
combination of output encoding and fonts that will print on another, and
vice versa. "Unprintable" in this sense is almost impossible to determine.
If you rather meant "control character" (*most* of which are unprintable)
there's Char.IsControl() for single characters and the "C" character class
in regular expressions. The following expression will determine if a string
contains any control characters:
Regex.IsMatch(s, @"\p{C}");
To exclude the control characters that do print, albeit as white space:
Regex.IsMatch(s, @"[\p{C}-[\s]]");
There are many more character classes, some combination of which possibly
being what you're after:
http://msdn.microsoft.com/library/20bw873z