using System; using System.IO; using System.Text.RegularExpressions; using System.Linq; public class Test { public static void Main() { var text = "there are big widgets in this phrase blue widgets too"; var words = "big blue widgets"; var pattern = $@"(\s*(? index % 2 == 0 && !string.IsNullOrWhiteSpace(str) ? $"{str}" : str)); Console.WriteLine(result); } }