using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var s = "123-234;FOO-456;45-67;FOO-FOO;890;FOO-123;11-22;123;123;44-55;098-567;890;123-FOO;"; var rx = new Regex(@"(?<=^|;)((?\d+-\d+)|(?\d+))(?=$|;)", RegexOptions.ExplicitCapture); var result = rx.Matches(s) .Cast() .Select(x => x.Groups["range"].Success ? x.Groups["range"].Value : x.Groups["integer"].Value ).ToList(); foreach (var x in result) Console.WriteLine(x); } }