Regular Expression

J

John

How can I use regular expression to detect all the unprintable characters?

Please help.

Thanks.
 
J

Jeroen Mostert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Regular Expression 2
Regular Expression Help 1
regular expression 7
Regular expression 5
regular expression NxM 9
Regular expression 4
regular expressions 5
One more regular expression 4

Top