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 = "123-234;FOO-456;45-67;FOO-FOO;890;FOO-123;11-22;123;123;44-55;098-567;890;123-FOO;";
  12. var rx = new Regex(@"(?<=^|;)((?<range>\d+-\d+)|(?<integer>\d+))(?=$|;)", RegexOptions.ExplicitCapture);
  13. var result = rx.Matches(s)
  14. .Cast<Match>()
  15. .Select(x => x.Groups["range"].Success ?
  16. x.Groups["range"].Value : x.Groups["integer"].Value
  17. ).ToList();
  18. foreach (var x in result)
  19. Console.WriteLine(x);
  20. }
  21. }
Success #stdin #stdout 0.13s 25000KB
stdin
Standard input is empty
stdout
123-234
45-67
890
11-22
123
123
44-55
098-567
890