fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var arrayOfWordsToSplitOn = new List<string> { "cat", "dog" };
  12. var s = "My cat and my dog are very lazy";
  13. var pattern = string.Format(@"\s*\b({0})\b\s*", string.Join("|", arrayOfWordsToSplitOn));
  14. var results = Regex.Split(s, pattern).Where(x => !String.IsNullOrWhiteSpace(x)).ToList();
  15. foreach (var res in results)
  16. Console.WriteLine(res);
  17. }
  18. }
Success #stdin #stdout 0.03s 134592KB
stdin
Standard input is empty
stdout
My
cat
and my
dog
are very lazy