In your example, the regular expression will succeed for a single character, since it searches for the last character, if it is not uppercase, and your string has such a character.
The regular expression should be changed to Regex r = new Regex("[^AZ]"); .
(updated after comments by @Chris)
However, for your purpose, regex is what you want - just use Matches .
eg:.
foreach (Match item in r.Matches(myString)) { Console.WriteLine(item.ToString() + " is invalid"); }
Or if you want a single line:
foreach (Match item in r.Matches(myString)) { str += item.ToString() + ", "; } Console.WriteLine(str + " are invalid");
source share