Does this work? I wrote the code directly into this post, so I may have made errors Code: string pattern = @"(?<Number>\d+?)\.\s+?(?<License>(?:\d|\w){8}-(?:(?:\d|\w){4}-){3}(?:\d|\w){12})"; Regex regex = new Regex(pattern); MatchCollection matches = regex.Matches(yourStringWithData); // This can be changed to <int, string> if you want to convert the number into an integer type with int.Parse() or int.TryParse(). Dictionary<string, string> licenses = new Dictionary<string, string>(); foreach (Match match in matches) { string number = match.Groups["Number"].Value; string license = match.Groups["License"].Value; // Use the matched strings licenses.Add(number, license); } // All licenses can now be accessed from the dictionary
Glad you got it working This is a revised version that disregards the 0.'s - just posting it for future reference Code: using System.Collections.Generic; using System.Text.RegularExpressions; string pattern = @"(?:\d|\w){8}-(?:(?:\d|\w){4}-){3}(?:\d|\w){12}"; Regex regex = new Regex(pattern); MatchCollection matches = regex.Matches(yourStringWithData); List<string> licenses = new List<string>(); foreach (Match match in matches) { string license = match.Value.ToLowerInvariant().Trim(); // For casing consistency, and removes eventual spaces licenses.Add(license); }