fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. Regex regex = new Regex("(([_ ]*[a-z]+)_ ?)+([_ ]*[a-z]+)");
  9. string str = "a_b_c_ _ _abc_ _ _ _abcd";
  10.  
  11. Match match = regex.Match(str);
  12. for (int i = 2; i < match.Groups.Count; i++) {
  13.  
  14. foreach (Capture capture in match.Groups[i].Captures)
  15. Console.Write("[{0}]", capture.Value);
  16. }
  17.  
  18. Console.ReadLine();
  19. }
  20. }
Success #stdin #stdout 0.07s 33984KB
stdin
Standard input is empty
stdout
[a][b][c][_ _abc][_ _ _abcd]