fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Collections.Specialized;
  4. class Program {
  5.  
  6. static void Main() {
  7. string yourstring = @"1.1 - Hello
  8. 1.2 - world!
  9. 2.1 - Some
  10. data
  11. here and it contains some 32 digits so i cannot use \D+
  12. 2.2 - Etc..";
  13. var resultList = new StringCollection();
  14. try {
  15. var yourRegex = new Regex(@"(?sm)^\d+\.\d+\s*-\s*((?:.(?!^\d+\.\d+))*)");
  16. Match matchResult = yourRegex.Match(yourstring);
  17. while (matchResult.Success) {
  18. resultList.Add(matchResult.Groups[1].Value);
  19. Console.WriteLine("Whole Match: " + matchResult.Value);
  20. Console.WriteLine("Group 1: " + matchResult.Groups[1].Value + "\n");
  21. matchResult = matchResult.NextMatch();
  22. }
  23. } catch (ArgumentException ex) {
  24. // Syntax error in the regular expression
  25. }
  26.  
  27. Console.WriteLine("\nPress Any Key to Exit.");
  28. Console.ReadKey();
  29. } // END Main
  30. } // END Program
  31.  
Success #stdin #stdout 0.08s 34136KB
stdin
Standard input is empty
stdout
Whole Match: 1.1 - Hello
Group 1: Hello

Whole Match: 1.2 - world!
Group 1: world!

Whole Match: 2.1 - Some
data
here and it contains some 32 digits so i cannot use \D+
Group 1: Some
data
here and it contains some 32 digits so i cannot use \D+

Whole Match: 2.2 - Etc..
Group 1: Etc..


Press Any Key to Exit.