fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Collections.Specialized;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var smilies = new OrderedDictionary
  10. {
  11. {@">:(", "smile_angryx24"}, // Put this one first
  12. {@":(", "smile_sadx24"},
  13. };
  14. string incomingtext = @"This is sad... :( But this makes me so angry!!! >:(";
  15. foreach (string smiley in smilies.Keys)
  16. {
  17. var re = new Regex(@"(?<!(=""))" + Regex.Escape(smiley) + @"(?!(""))");
  18. // Second should be a negative lookahead ^^
  19. if (re.IsMatch(incomingtext))
  20. {
  21. string m2 = re.Replace(incomingtext, "<img src=\"/Content/themes/mavi/img/custom/smiles/" + smilies[smiley] + ".png\" alt=\"" + smiley + "\"/>");
  22. incomingtext = m2;
  23. }
  24. }
  25. Console.WriteLine(incomingtext);
  26. }
  27. }
Success #stdin #stdout 0.07s 34888KB
stdin
Standard input is empty
stdout
This is sad... <img src="/Content/themes/mavi/img/custom/smiles/smile_sadx24.png"  alt=":("/> But this makes me so angry!!! <img src="/Content/themes/mavi/img/custom/smiles/smile_angryx24.png"  alt=">:("/>