Advertisement
viligen

fancy_barcodes_2

Dec 3rd, 2021
900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. import re
  2.  
  3. pattern_valid = r"@#+([A-Z][A-Za-z0-9]{4,}[A-Z])@#+"
  4. n = int(input())
  5.  
  6. for _ in range(n):
  7.     barcode = input()
  8.     match = re.search(pattern_valid, barcode)
  9.     if not match:
  10.         print("Invalid barcode")
  11.     else:
  12.         group = "".join([n for n in match.group(1) if n.isdigit()])
  13.         if not group:
  14.             group = "00"
  15.         print(f"Product group: {group}")
  16.  
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement