fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Collections.Specialized;
  4. class Program
  5. {
  6. static void Main() {
  7. var myRegex = new Regex(@"&#x\w+;|([257])");
  8. string s1 = @"hello Sam, how are you 27‏ do not worry 5
  9. how are you  why you are not OK.ℏ and ‍ ";
  10.  
  11. string replaced = myRegex.Replace(s1, delegate(Match m) {
  12. switch (m.Groups[1].Value) {
  13. case "2": return "a";
  14. case "7": return "b";
  15. case "5": return "c";
  16. default: return m.Value;
  17. }
  18. });
  19. Console.WriteLine("\n" + "*** Replacements ***");
  20. Console.WriteLine(replaced);
  21.  
  22.  
  23. Console.WriteLine("\nPress Any Key to Exit.");
  24. Console.ReadKey();
  25.  
  26. } // END Main
  27. } // END Program
Success #stdin #stdout 0.08s 34760KB
stdin
Standard input is empty
stdout
*** Replacements ***
hello Sam, how are you ab‏ do not worry c
how are you  why you are not OK.ℏ  and ‍ 

Press Any Key to Exit.