fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. var data = new[] {
  9. "AB7YT1M=ABC",
  10. "AB10YT1M=ABC",
  11. "AB30YT1M=ABC",
  12. "ABCDEF1Y1M=A",
  13. "ABCDEF34Y6M=A",
  14. "ABCDEF7M=A"
  15. };
  16. Regex r = new Regex(@"(?:(\d+)Y)?T?(?:(\d+)M)");
  17. foreach (var s in data) {
  18. var m = r.Match(s);
  19. if (m.Success) {
  20. var yy = m.Groups[1];
  21. var mm = m.Groups[2];
  22. Console.WriteLine("Y='{0}', M='{1}'", yy, mm);
  23. }
  24. }
  25. }
  26. }
Success #stdin #stdout 0.08s 24520KB
stdin
Standard input is empty
stdout
Y='7', M='1'
Y='10', M='1'
Y='30', M='1'
Y='1', M='1'
Y='34', M='6'
Y='', M='7'