using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var texts = new List { "[10 .. 15)", "[100 .. 15.2)", "[10.431 .. 15)", "[-10.3 .. -5)", "[-10.4 .. 5.12)", "[10.4312 .. -5.1232)" }; var pattern = new Regex(@"^\[(-?\d+(?:\.\d+)?) \.\. (-?\d+(?:\.\d+)?)\)$"); foreach (var s in texts) { Console.WriteLine($"---- {s} ----"); var match = pattern.Match(s); if (match.Success) { Console.WriteLine($"Group 1: {match.Groups[1].Value}, Group 2: {match.Groups[2].Value}"); } else { Console.WriteLine($"No match found in '{s}'."); } } } }