fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var s = "START\r\n\r\nCity: Los Angeles\r\n- Item: 48\r\n- Item: 57\r\n- Item: 92\r\n- Item: 77\r\n\r\nCity: Austin\r\n- Item: 44\r\n- Item: 88\r\n";
  12. var pattern = @"(?m)^City:\s*Los Angeles(?:\s*-\s*Item:\s*(?<itemnum>\d+))+";
  13. var result = Regex.Matches(s, pattern)
  14. .Cast<Match>().SelectMany(p => p.Groups["itemnum"].Captures
  15. .Cast<Capture>()
  16. .Select(x => x.Value));
  17. Console.WriteLine(string.Join(", ", result));
  18. }
  19. }
Success #stdin #stdout 0.07s 134592KB
stdin
Standard input is empty
stdout
48, 57, 92, 77