fork download
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var p = new[] {
  10. @"aaa[0-9]{2}\.zip",
  11. @"bbb[0-9]{2}\.zip"
  12. };
  13. var pat = new Regex($"({string.Join(")|(", p)})");
  14. var match = pat.Match("We have bbb12.zip match");
  15. //var grps = match.Groups.Cast<Group>();
  16. for (var n=1; n <= p.Count(); n++)
  17. {
  18. if (match.Groups[n].Success)
  19. {
  20. Console.Write("{0} group matched, the pattern is {1}", n, p[n-1]);
  21. break;
  22. }
  23. }
  24. }
  25. }
Success #stdin #stdout 0.06s 22068KB
stdin
Standard input is empty
stdout
2 group matched, the pattern is bbb[0-9]{2}\.zip