Matching extended ASCII characters in .NET Regex
I've tried to reproduce your error and found nothing wrong with your code:
String pattern = @"[\x20-\xFF]";
// All ANSII
for (Char ch = ' '; ch <= 255; ++ch)
if (!Regex.IsMatch(ch.ToString(), pattern))
Console.Write("Failed!");
// All non-ANSII
for (Char ch = (Char)256; ch < Char.MaxValue; ++ch)
if (Regex.IsMatch(ch.ToString(), pattern))
Console.Write("Failed!");
Then I've examined your samples:
((int)'ç').ToString("X2"); // <- returns E7, OK
((int)'œ').ToString("X2"); // <- returns 153 NOT x9C
Note, that 'œ' (x153)
is actually outside [0x20..0xFF]
and that's why matching returns false
. So I guess that you've got a typo