using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace GregoryAdam.Test { public static class testegex { public static void Main() { // 1 // 1234567890121234567890123456712345678901234567812345678901234567890112345678901234567890123456789011234567890 string s = @"BX00027025 AD ME CW NO'S ALLOCATED TO KEW TRUNKS 29/03/1994"; string pattern = "^(.{12})(.{17})(.{18})(.{21})(.{31})(.{10})$"; MatchCollection matches = Regex.Matches(s, pattern); if (matches.Count != 1) { Console.WriteLine("problem"); } else { Match match = matches[0]; GroupCollection groups = match.Groups; // groups[0] is the whole line // start at 1 for (int i = 1; i < groups.Count; i++) { Console.WriteLine("{0}:{1}", i, groups[i].Value); } Console.ReadLine(); } } } }