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 regex = new Regex(@"(?<=headerb)[\r\n]*(?:aa(?<number>\d+)aaa[\r\n]*)+(?=headerc)", RegexOptions.Singleline);
  10. var match = regex.Match(_input);
  11. if (match.Success)
  12. {
  13. foreach (var number in match.Groups["number"].Captures.Cast<Capture>())
  14. {
  15. Console.WriteLine(number);
  16. }
  17. }
  18. }
  19.  
  20. private static readonly string _input = @"headera
  21. aa1aaa
  22. aa2aaa
  23. aa3aaa
  24.  
  25. headerb
  26. aa4aaa
  27. aa5aaa
  28. aa6aaa
  29.  
  30. headerc
  31. aa7aaa
  32. aa8aaa
  33. aa9aaa";
  34. }
Success #stdin #stdout 0.13s 24688KB
stdin
Standard input is empty
stdout
4
5
6