fork(1) 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 texts = new List<string> { "[10 .. 15)", "[100 .. 15.2)", "[10.431 .. 15)", "[-10.3 .. -5)", "[-10.4 .. 5.12)", "[10.4312 .. -5.1232)" };
  12. var pattern = new Regex(@"^\[(-?\d+(?:\.\d+)?) \.\. (-?\d+(?:\.\d+)?)\)$");
  13. foreach (var s in texts)
  14. {
  15. Console.WriteLine($"---- {s} ----");
  16. var match = pattern.Match(s);
  17. if (match.Success)
  18. {
  19. Console.WriteLine($"Group 1: {match.Groups[1].Value}, Group 2: {match.Groups[2].Value}");
  20. }
  21. else
  22. {
  23. Console.WriteLine($"No match found in '{s}'.");
  24. }
  25. }
  26. }
  27. }
Success #stdin #stdout 0.06s 27744KB
stdin
Standard input is empty
stdout
---- [10 .. 15) ----
Group 1: 10, Group 2: 15
---- [100 .. 15.2) ----
Group 1: 100, Group 2: 15.2
---- [10.431 .. 15) ----
Group 1: 10.431, Group 2: 15
---- [-10.3 .. -5) ----
Group 1: -10.3, Group 2: -5
---- [-10.4 .. 5.12) ----
Group 1: -10.4, Group 2: 5.12
---- [10.4312 .. -5.1232) ----
Group 1: 10.4312, Group 2: -5.1232