using System; using System.Text.RegularExpressions; using System.IO; public class Test { public static void Main() { var searchString = "to find"; var pattern = @"\b" + searchString + @"\b"; //searchString is passed in. Regex rgx = new Regex(pattern); var sentence = "I need to find a string in this sentence!"; Match match = rgx.Match(sentence); if (match.Success) { Console.WriteLine(match.Value); } } }