This pair of regular expressions should work for the case you showed us.
/// <summary> /// Regular expression built for C# on: Sun, Aug 25, 2013, 12:55:52 PM /// Using Expresso Version: 3.0.4334, http://www.ultrapico.com /// /// A description of the regular expression: /// /// Match expression but don't capture it. [Lucky Stars\r\n] /// Lucky Stars\r\n /// Lucky /// Space /// Stars /// Carriage return /// New line /// [Numbers]: A named capture group. [.*\r\n], exactly 5 repetitions /// .*\r\n /// Any character, any number of repetitions /// Carriage return /// New line /// /// /// </summary> public static Regex regex = new Regex( "(?:Lucky Stars\\r\\n)(?<Numbers>.*\\r\\n){5}", RegexOptions.CultureInvariant | RegexOptions.Compiled ); public static Regex replaceRegex = new Regex( "(\\s-.*\r\n)", RegexOptions.CultureInvariant | RegexOptions.Compiled );
And the code for finding numbers can be as follows:
var InputText = @"Lucky Stars A 1 8 22 37 47 48 - 03 10 B11 15 26 43 44 - 05 06 C 08 23 27 28 29 - 02 09 D06 09 21 26 29 - 01 05 E 06 07 21 22 45 - 04 05 Your raffle numbers"; Match m = regex.Match(InputText); var numbers = m.Groups["Numbers"].Captures .OfType<Capture>() .Select(c => replaceRegex.Replace(c.Value, "").Replace(" ", ""));
But I doubt that using regex is the best solution when you use the OCR technique to get text from an image.
source share