fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var input = "aaa 12 bbb 123,456,789 ccc 34";
  12. foreach (var value in GetValues(input))
  13. Console.WriteLine(value);
  14. }
  15.  
  16. public static IEnumerable<string> GetValues(string input)
  17. {
  18. // Suppose regex could be any regex
  19. var regex = new Regex(@"(?:(?<concat>\d+),?)+");
  20.  
  21. foreach (Match match in regex.Matches(input))
  22. {
  23. // Does this regex have our special feature?
  24. if (regex.GroupNumberFromName("concat") >= 0)
  25. {
  26. // Concat the captured values
  27. var captures = match.Groups["concat"].Captures.Cast<Capture>().Select(c => c.Value).ToArray();
  28. yield return String.Concat(captures);
  29. }
  30. else
  31. {
  32. // This is a normal regex
  33. yield return match.Value;
  34. }
  35. }
  36. }
  37. }
Success #stdin #stdout 0.08s 34216KB
stdin
Standard input is empty
stdout
12
123456789
34