#!/usr/bin/env python3 """ Analyze barcode structure """ test_barcode = "[)>06PSAM9019-ND1PJL-100-25-T30PSAM9019-NDK1K9530640910K1172401379D25291T34755734000711K14LCNQ1811ZPICK12Z268520113Z99999920Z00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" print("Barcode structure analysis:") print(f"Total length: {len(test_barcode)}") print() # Look for patterns import re # Find all capital letters followed by content pattern = r'([A-Z]+)([^A-Z]*)' matches = re.findall(pattern, test_barcode) print("Pattern matches (Letter + Content):") for i, (letter, content) in enumerate(matches[:20]): if content: print(f" {letter}: '{content}'") print("\n" + "="*70) # Check if there are specific field markers markers = ['30P', '1P', 'Q', 'K', 'D', 'T', 'Z', 'P'] for marker in markers: if marker in test_barcode: idx = test_barcode.find(marker) print(f"Found '{marker}' at position {idx}: {test_barcode[idx:idx+20]}") print("\n" + "="*70) # Try to identify the structure # [)>06 is ANSI MH10.8.2 format if test_barcode.startswith('[)>06'): print("This is ANSI MH10.8.2 barcode format") print("Format: [)>06 + Format Identifier + GS + Data + RS + EOT") # The data section should start after the format header data_start = 5 # After [)>06 # Look for common field identifiers print("\nSearching for field identifiers:") # Common identifiers in ANSI format: # P = Part Number # 1P = Supplier Part Number # 30P = Customer Part Number # Q = Quantity # K = Batch/Lot # Try a different approach - look for explicit markers text = test_barcode[5:] # Skip header # Find 30P marker if '30P' in text: idx = text.index('30P') after_30p = text[idx+3:] # Extract until next capital letter or known marker part_match = re.match(r'([A-Z0-9\-]+)', after_30p) if part_match: print(f" Part (30P): {part_match.group(1)}") # Find 1P marker if '1P' in text: idx = text.index('1P') after_1p = text[idx+2:] part_match = re.match(r'([A-Z0-9\-]+)', after_1p) if part_match: print(f" Supplier Part (1P): {part_match.group(1)}") # Find P (might be part number) if test_barcode.startswith('[)>06P'): after_p = test_barcode[6:] part_match = re.match(r'([A-Z0-9\-]+)', after_p) if part_match: print(f" Part (P): {part_match.group(1)}") # Find Q for quantity if 'Q' in text: # Look for Q followed by digits q_matches = re.findall(r'Q(\d+)', text) if q_matches: print(f" Quantity (Q): {q_matches}")