fork download
  1. using System;
  2. using System.Linq.Expressions;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. string str = "i<A> | n<B> | <C>";
  12. MatchCollection matches = Regex.Matches(str, @"^(?<first>[A-Za-z0-9]*)<(?<second>[^<>]*)>(?:\s+\|\s+(?<first>[A-Za-z0-9]*)<(?<second>[^<>]*)>)+$");
  13.  
  14. foreach (Match match in matches)
  15. {
  16. match.Groups["first"].Captures
  17. .Select(c => c.Value)
  18. .Zip(match.Groups["second"].Captures.Select(c => c.Value), (x, y) => Tuple.Create(x, y))
  19. .ToList()
  20. .ForEach(t => Console.WriteLine("first: {0}, second: {1}", t.Item1, t.Item2));
  21. }
  22. }
  23. }
Success #stdin #stdout 0.1s 30520KB
stdin
Standard input is empty
stdout
first: i, second: A
first: n, second: B
first: , second: C