// 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.Text.RegularExpressions; namespace E { public class MainClass { private static Regex re = new Regex("(?:^(?:korrekt1)|(?:korrekt2))(?: )([^ ]+)"); public static void Main(string[] args) { string s = @"abc def korrekt1 FindMig1 adsf hsdf abc def fghd korrekt2 FindMig2 adsf hsdf"; StringReader sr = new StringReader(s); string line; while((line = sr.ReadLine()) != null) { if(re.IsMatch(line)) { Console.WriteLine(re.Match(line).Groups[1].Value); } } } } }