fork(7) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.IO;
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. string body = "hello [context.world]!! hello [context.anotherworld] and [context.text]";
  11. Dictionary<string, string> dyn = new Dictionary<string, string>(){
  12. {"world", "earth"}, {"anotherworld", "mars"}
  13. };
  14. Console.WriteLine(Regex.Replace(body, @"\[context\.(\w+)]",
  15. m => dyn.ContainsKey(m.Groups[1].Value) ? dyn[m.Groups[1].Value] : m.Value));
  16. }
  17.  
  18. }
Success #stdin #stdout 0.04s 134720KB
stdin
Standard input is empty
stdout
hello earth!! hello mars and [context.text]