// 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.Text.RegularExpressions; namespace E { public class Program { private static readonly Regex re = new Regex(@"(?:SECTION\r\n)(.*?)(?:ENDSECTION\r\n)", RegexOptions.Singleline | RegexOptions.Compiled); public static void Parse(string s) { foreach(Match m in re.Matches(s)) { Console.WriteLine("section=" + m.Groups[1].Value); } } public static void Main(string[] args) { string s = @"SECTION hello this is my section it can use SECTION or ENDSECTION if I want it to and can be multi lined ENDSECTION SECTION Another Section, can be any amount of sections in a file ENDSECTION "; Parse(s); } } }