fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.IO;
  6. using System.Text;
  7.  
  8. public class Test
  9. {
  10. public static void Main()
  11. {
  12. string pattern = @"\A(?:\.(?<exName>[A-Za-z]+)\((?<exVal>[^()]*)\))+\z";
  13.  
  14. var strings = new List<string>() {
  15. ".Foo().Bar(20).Baz(Hello)",
  16. ".Foo().Bar(30)k.Baz(Hi)hgjfvg",
  17. ".Foo(test).Bar(40).Baz(Bye)"
  18. };
  19. foreach (var input in strings)
  20. {
  21. foreach (Match m in Regex.Matches(input, pattern))
  22. {
  23. m.Groups["exName"]
  24. .Captures.Select(c => c.Value)
  25. .Zip(
  26. m.Groups["exVal"].Captures.Select(c => c.Value),
  27. (exName, exVal) => exName + " -> " + exVal
  28. ).ToList()
  29. .ForEach(s => Console.WriteLine(s));
  30. Console.WriteLine("---------------");
  31. }
  32. }
  33. }
  34. }
Success #stdin #stdout 0.1s 28508KB
stdin
Standard input is empty
stdout
Foo -> 
Bar -> 20
Baz -> Hello
---------------
Foo -> test
Bar -> 40
Baz -> Bye
---------------