fork download
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. string test = "viv-ek is a good boy.Mah - esh is Cra - zy.";
  10. var words =
  11. Regex
  12. .Matches(test, @"(?<part>\w+)(\s*-\s*(?<part>\w+))+\b")
  13. .Cast<Match>()
  14. .Select(
  15. x => string.Join(
  16. string.Empty,
  17. x.Groups["part"].Captures.Cast<Capture>().SelectMany(capture => capture.Value)))
  18. .ToList();
  19. words.ForEach(Console.WriteLine);
  20. }
  21. }
Success #stdin #stdout 0.11s 24448KB
stdin
Standard input is empty
stdout
vivek
Mahesh
Crazy