fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var text = "This is a /Sample Text: in a sentence";
  12. var oldValue = "/Sample Text:";
  13. var newValue = "sample text";
  14. var matchCase = RegexOptions.IgnoreCase;
  15. var result = Regex.Replace(text, $@"(?!\B\w){Regex.Escape(oldValue)}(?<!\w\B)", newValue, matchCase);
  16. Console.WriteLine(result);
  17. }
  18. }
Success #stdin #stdout 0.07s 31364KB
stdin
Standard input is empty
stdout
This is a sample text in a sentence