fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text.RegularExpressions;
  5. using System.Linq;
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. var lst = new List<string> {"3.AAA", "AAA.BBB", "AAA.3.BBB", "AAA.3.B555B", "AAA.3.BBB.4",
  11. "AAA.3.BBB.4.CCC", "AAA.3.BBB.CCC", "AAA.3.BBB.CCC.4", "AAA.3.BBB.CCC.4.DDD",
  12. "ZZZ.AAA.3.BBB","ZZZ.AAA.3.BBB.4","ZZZ.AAA.3.BBB.4.CCC", "ZZZ.AAA.3.BBB.CCC",
  13. "ZZZ.AAA.3.BBB.CCC.4", "ZZZ.AAA.3.BBB.CCC.4.DDD"};
  14. var rx = new Regex(@"^(?:(?!\d+\.)[^\s.]+\.)+\d+(?:\.(?!\d+(?=\.|$))[^\s.]+)+$",
  15. RegexOptions.Compiled | RegexOptions.ECMAScript);
  16. foreach (var s in lst)
  17. {
  18. if (rx.IsMatch(s))
  19. Console.WriteLine(s);
  20. }
  21. }
  22.  
  23.  
  24. }
  25.  
  26.  
Success #stdin #stdout 0.04s 19516KB
stdin
Standard input is empty
stdout
AAA.3.BBB
AAA.3.B555B
AAA.3.BBB.CCC
ZZZ.AAA.3.BBB
ZZZ.AAA.3.BBB.CCC