// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.IO; using System.Net; using System.Text.RegularExpressions; class MainClass { public static void Main(string[] args) { string s = @"Header 1 - Item 1 - Item 2 - Item 3 Header 2 - Item 4 - Item 5 Header 3 - Item 6 - Item 7 - Item 8 - Item 9"; Parse(s); } public static void Parse(string s) { MatchCollection res = Regex.Matches(s,"(^[^-].+$)(\n^- .+$)*", RegexOptions.Multiline); for(int i = 0; i < res.Count; i++) { MatchCollection res2 = Regex.Matches(res[i].Groups[0].Value,"^- (.+)$", RegexOptions.Multiline); for(int j = 0; j < res2.Count; j++) { Console.WriteLine(res[i].Groups[1].Value.Replace("\r","") + " - " + res2[j].Groups[1].Value); } } } }