fork 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. var s = "Since there is limited overhead space on the plane, I assure you, there will be no fee for checking the bags, I can go ahead and fill out all the checked baggage forms for you.";
  11. var lst = new List<string>() {"no fee, I fill out the forms","some other"};
  12. var pattern = string.Format(@"(?s)\b(?:{0})\b",
  13. string.Join("|",
  14. lst.Select(x =>
  15. "(" + string.Join(@")\b(.*?)\b(",
  16. Regex.Split(x, @"\W+").Where(t => !string.IsNullOrWhiteSpace(t))
  17. ) + ")"
  18. )
  19. )
  20. );
  21. //Console.WriteLine(pattern);
  22. int cnt = 0;
  23. var res = Regex.Replace(s, pattern,
  24. g => string.Join("", g.Groups.Cast<Group>().Skip(1)
  25. .Where(f => !string.IsNullOrEmpty(f.Value))
  26. .SelectMany((b,i) => i % 2 == 0 ?
  27. "<b>" + b.Value + "</b>" : b.Value ) ));
  28. Console.WriteLine(res);
  29.  
  30.  
  31. }
  32. }
Success #stdin #stdout 0.04s 134720KB
stdin
Standard input is empty
stdout
Since there is limited overhead space on the plane, I assure you, there will be <b>no</b> <b>fee</b> for checking the bags, <b>I</b> can go ahead and <b>fill</b> <b>out</b> all <b>the</b> checked baggage <b>forms</b> for you.