fork(6) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Program
  5. {
  6. public static void Main()
  7. {
  8. string text = @"It is @google.com or @google w@google \@google \\@google";
  9. string result = SafeReplace(text,"@google", "some domain", true);
  10. Console.WriteLine(result);
  11. }
  12.  
  13.  
  14. public static string SafeReplace(string input, string find, string replace, bool matchWholeWord)
  15. {
  16. string textToFind = matchWholeWord ? string.Format(@"(?<!\S){0}(?!\S)", Regex.Escape(find)) : find;
  17. return Regex.Replace(input, textToFind, replace.Replace("$","$$"));
  18. }
  19. }
Success #stdin #stdout 0.03s 30688KB
stdin
Standard input is empty
stdout
It is @google.com or some domain w@google \@google \\@google