fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. string input = "Welcome {{friend}} Get my new {{id}} with {{anonymous}} People";
  12. Dictionary<string, string> mydict = new Dictionary<string, string> ();
  13. mydict.Add("friend", "<<My Friend>>");
  14. mydict.Add("id", "<<Your ID>>");
  15. string pattern = @"{{(.*?)}}";
  16. string regex = Regex.Replace(input, pattern, delegate(Match match) {
  17. string v = match.Groups[1].Value;
  18. return mydict.ContainsKey(v) ? mydict[v] : v;
  19. });
  20.  
  21. Console.WriteLine(regex);
  22. }
  23. }
Success #stdin #stdout 0.05s 19928KB
stdin
Standard input is empty
stdout
Welcome <<My Friend>> Get my new <<Your ID>> with anonymous People