fork(2) download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. var Snippet = "Jack and Jill went up the (hill) to fetch some water";
  11. var Highlights = new string[] { "Jack", "(hill)", "to" };
  12. var rx = string.Format(@"(?<!\w)(?:{0})(?!\w)",
  13. string.Join("|", Highlights.Select(p => Regex.Escape(p))));
  14. var res = Regex.Replace(Snippet, rx,
  15. "<span class=\"text-highlight\">$&</span>",
  16. RegexOptions.IgnoreCase);
  17. Console.WriteLine(res);
  18. }
  19. }
Success #stdin #stdout 0.11s 24432KB
stdin
Standard input is empty
stdout
<span class="text-highlight">Jack</span> and Jill went up the <span class="text-highlight">(hill)</span> <span class="text-highlight">to</span> fetch some water