fork 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 s = "widgets All men like widgets but some men like widgets more than others";
  10. var chunks = Regex.Split(s, @"(\s*\bwidgets\b\s*)");
  11. var result = string.Concat(chunks.Select((i, index) => index % 2 == 0 && !string.IsNullOrWhiteSpace(i) ? $"<b>{i}</b>" : i));
  12. Console.WriteLine(result);
  13. }
  14.  
  15.  
  16. }
  17.  
  18.  
Success #stdin #stdout 0.03s 134592KB
stdin
Standard input is empty
stdout
widgets <b>All men like</b> widgets <b>but some men like</b> widgets <b>more than others</b>