fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test {
  5. static bool HasOnlyOne(Match m, int g1, int g2) {
  6. if (!m.Success) {
  7. return false;
  8. }
  9. var has1 = m.Groups[g1].Success;
  10. var has2 = m.Groups[g2].Success;
  11. return !has1 || !has2;
  12. }
  13. public static void Main() {
  14. var r = new Regex(@"^[@][nN]([$]|[~][^~]*[~])?(-)?[1-9][0-9]*(-)?([$]|[~][^~]*[~])?$");
  15. string s;
  16. while ((s = Console.ReadLine()) != null) {
  17. var m = r.Match(s);
  18. bool good = HasOnlyOne(m, 1, 4) && HasOnlyOne(m, 2, 3);
  19. if (good) {
  20. Console.WriteLine("Match: {0}", s);
  21. } else {
  22. Console.WriteLine("Fail: {0}", s);
  23. }
  24. }
  25. }
  26.  
  27. }
  28.  
Success #stdin #stdout 0.02s 133888KB
stdin
@N$7-
@N-7$
@N$-7
@N7-$
@N$5$
@N$-5-
@N-5-
@N7$-
@N-$7
stdout
Match: @N$7-
Match: @N-7$
Match: @N$-7
Match: @N7-$
Fail: @N$5$
Fail: @N$-5-
Fail: @N-5-
Fail: @N7$-
Fail: @N-$7