fork download
  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4.  
  5. class M
  6. {
  7. static void Main(string[] args)
  8. {
  9. string[] x =new[]{ @"asoetuh T.C.A. satoeuhs TaCaA",
  10. @"T.C.A. basoetuhase",
  11. @"aoethT.C.A.tnetnn"
  12. };
  13.  
  14. string[] y = new[] {
  15. @"asoetu_T.C.A.aoesuth", "_T.C.A. satoheustn", "satoheu _T.C.A.", "aoeu TbCaA"
  16. };
  17.  
  18. string repl = "%%%%";
  19.  
  20. foreach (var item in x)
  21. {
  22. Console.WriteLine("{0} -> {1}", item, Regex.Replace(item, @"(?<!_)" + Regex.Escape(@"T.C.A."), repl));
  23. }
  24.  
  25. foreach (var item in y)
  26. {
  27. Console.WriteLine("{0} -> {1}", item, Regex.Replace(item, @"(?<!_)" + Regex.Escape(@"T.C.A."), repl));
  28. }
  29. }
  30. }
Success #stdin #stdout 0.06s 34136KB
stdin
Standard input is empty
stdout
asoetuh T.C.A. satoeuhs TaCaA -> asoetuh %%%% satoeuhs TaCaA
T.C.A. basoetuhase -> %%%% basoetuhase
aoethT.C.A.tnetnn -> aoeth%%%%tnetnn
asoetu_T.C.A.aoesuth -> asoetu_T.C.A.aoesuth
_T.C.A. satoheustn -> _T.C.A. satoheustn
satoheu _T.C.A. -> satoheu _T.C.A.
aoeu TbCaA -> aoeu TbCaA