using System.Globalization;
using System.Text.RegularExpressions;
public static void Main()
string text = "It is @google.com or @google";
string result = SafeReplace(text,"@google", "some domain.", true);
string resultNoAtrate = SafeReplace(text,"google", "some domain.", true);
Console.WriteLine(result);
Console.WriteLine(resultNoAtrate);
public static string SafeReplace(string input, string find, string replace, bool matchWholeWord)
string textToFind = matchWholeWord ? string.Format(@"\b{0}\b", find) : find;
return Regex.Replace(input, textToFind, replace);