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. OrderedDictionary Links = new OrderedDictionary();
  10. Links.Add("Learn more about adding manuals and labels", "2");
  11. Links.Add("Delete Manuals and Labels", "3");
  12. Links.Add("manuals and labels", "1");
  13.  
  14. string text = "Having trouble with your manuals and labels? Learn more about adding manuals and labels. Need to get rid of them? Try to delete manuals and labels.";
  15.  
  16. foreach (string termToFind in Links.Keys)
  17. {
  18. Regex _regex = new Regex(@"\b" + termToFind + @"s?\b(?![^<>]*</)", RegexOptions.IgnoreCase);
  19. text = _regex.Replace(text, @"<a href=""" + Links[termToFind] + @".html"">$&</a>");
  20. }
  21. Console.WriteLine(text);
  22. }
  23. }
Success #stdin #stdout 0.08s 34208KB
stdin
Standard input is empty
stdout
Having trouble with your <a href="1.html">manuals and labels</a>? <a href="2.html">Learn more about adding manuals and labels</a>. Need to get rid of them? Try to <a href="3.html">delete manuals and labels</a>.