using System; using System.Text.RegularExpressions; public class Test { public static void Main() { String word = @"hello"; String input = @"hello. I am a string. hello friend. Many hellos. hello .hello"; Console.WriteLine("--- Input ---" + Environment.NewLine + input + Environment.NewLine); Console.WriteLine("--- Matches ---"); Regex regex = new Regex(@"(?<=\s)\b" + word + @"\b|\b" + word + @"\b(?=[\s\.])"); MatchCollection mc = regex.Matches(input); foreach(Match m in mc) { Console.WriteLine(m.Value + " - " + m.Index.ToString()); } } }