fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string s = "W\"oo\\lworth's";
  9. string pattern = "(['^$.|?*+()\\\\])";
  10. string replacement = "\\$1";
  11.  
  12. Regex rgx = new Regex(pattern);
  13. string t = rgx.Replace(s, replacement);
  14.  
  15. Console.WriteLine("Original String: {0}", s);
  16. Console.WriteLine("Replacement String: {0}", t);
  17. }
  18. }
Success #stdin #stdout 0.06s 27120KB
stdin
Standard input is empty
stdout
Original String: W"oo\lworth's
Replacement String: W"oo\\lworth\'s