using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RegExpTest { class Program { static void Main(string[] args) { Console.WriteLine(ICRFormat("16Mh1234")); Console.WriteLine(ICRFormat("15D35999")); Console.WriteLine(ICRFormat("115D35999")); Console.Read(); } static String ICRFormat(String UnformattedICR) { System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^(\\d\\d)([A-Z]{1,2})(\\d{1,6})$", System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.MatchCollection matches = regex.Matches(UnformattedICR); if (matches.Count == 1) { System.Text.RegularExpressions.Match match = matches[0]; return match.Groups[1] + " " + match.Groups[2].ToString().ToUpper() + " " + match.Groups[3]; } return "Invalid Entry"; } } }