using System; using System.Text.RegularExpressions; namespace RegExApplication { public class Program { public static void Main(string[] args) { string input = "word1 abcdkl word2"; Regex regex = new Regex(@"^(?=.*\bword1\b)(?=.*\bword2\b).*$"); Match match = regex.Match(input); if (match.Success) { Console.WriteLine(match.Groups[0].Value); } } } }