fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string[] fail = {"ABCDacbd", "ACDE", "ABCDE\n", "_01234", "ABCDÉ", "ABCD́Ē", "ABCDEF_", "A_B_CDEF", "AB_C", "1234567890123456789012345", "123456_789012345678901234"};
  9. string[] ok = {"ACBDEF", "01234", "ABC_DE1", "123456789012345678901234", "12345_789012345678901234"};
  10.  
  11. foreach (string s in fail) {
  12. Console.WriteLine(s + " " + Validate(s));
  13. }
  14. Console.WriteLine();
  15.  
  16. foreach (string s in ok) {
  17. Console.WriteLine(s + " " + Validate(s));
  18. }
  19. }
  20.  
  21. private static bool Validate(string str) {
  22. if (str.Length < 5 || str.Length > 24) {
  23. return false;
  24. }
  25.  
  26. return Regex.IsMatch(str, @"^[A-Z0-9]+(?:_[A-Z0-9]+)?\z");
  27. }
  28. }
Success #stdin #stdout 0.07s 24472KB
stdin
Standard input is empty
stdout
ABCDacbd False
ACDE False
ABCDE
 False
_01234 False
ABCDÉ False
ABCD́Ē False
ABCDEF_ False
A_B_CDEF False
AB_C False
1234567890123456789012345 False
123456_789012345678901234 False

ACBDEF True
01234 True
ABC_DE1 True
123456789012345678901234 True
12345_789012345678901234 True