Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- class Program
- {
- static void Main()
- {
- string regex1 = @"\A\@#+[A-Z]([A-Za-z\d]{4,})[A-Z]\@#+\Z";
- string regex2 = @"\d";
- int numberOfProducts = int.Parse(Console.ReadLine());
- for (int i = 0; i < numberOfProducts; i++)
- {
- string entry = Console.ReadLine();
- Match match = Regex.Match(entry, regex1);
- if (match.Success)
- {
- string rawData = match.Groups[1].Value;
- MatchCollection digits = Regex.Matches(rawData, regex2);
- string productGroup = string.Empty;
- if (digits.Count > 0)
- {
- foreach (Match digit in digits)
- productGroup += digit;
- }
- else
- {
- productGroup = "00";
- }
- Console.WriteLine($"Product group: {productGroup}");
- }
- else
- Console.WriteLine("Invalid barcode");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement