fork(1) download
  1. using System;
  2. using System.IO;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var text = "there are big widgets in this phrase blue widgets too";
  10. var words = "big blue widgets";
  11. var pattern = $@"(\s*(?<!\w)(?:{string.Join("|", words.Split(' ').Select(Regex.Escape))})(?!\w)\s*)";
  12. string result = string.Concat(Regex.Split(text, pattern, RegexOptions.IgnoreCase).Select((str, index) =>
  13. index % 2 == 0 && !string.IsNullOrWhiteSpace(str) ? $"<b>{str}</b>" : str));
  14. Console.WriteLine(result);
  15. }
  16.  
  17.  
  18. }
  19.  
  20.  
Success #stdin #stdout 0.04s 134592KB
stdin
Standard input is empty
stdout
<b>there are</b> big widgets <b>in this phrase</b> blue widgets <b>too</b>