fork(1) download
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. var line = "Keeping the line intact, replace me, but not you, keep this too.\n\nRetaining me, replace one, but not two, ignore three.";
  11. var res = Regex.Replace(line, @"replace (?<target>.*), but not (?<source>.*),",
  12. m => "replace " + m.Groups["source"].Value.Replace("o", "1") + ", but not " + m.Groups["source"].Value + ",");
  13. Console.WriteLine(res);
  14. }
  15. }
Success #stdin #stdout 0.11s 24696KB
stdin
Standard input is empty
stdout
Keeping the line intact, replace y1u, but not you, keep this too.

Retaining me, replace tw1, but not two, ignore three.