using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var rx = @"(WordA\s)?(?:WordB\s)?WordC"; var strings = new List {"WordC", "WordB WordC", "WordA WordC", "WordA WordB WordC"}; foreach (var s in strings) { var m = Regex.Match(s, rx); Console.WriteLine("{0}: {1}", s, (m.Groups[1].Success ? "NO MATCH" : m.Value)); } } }