JEI_Import_Documents-App/scripts/test_pair_re.py

29 lines
872 B
Python
Raw Normal View History

"""Quick test of pair_re against sample lines."""
import re
pair_re = re.compile(
r"(\d+(?:[,.]\d+)?)\s+("
r"JEI[A-Z0-9][A-Z0-9\-/\.]*"
r"|DRILL\-[A-Z0-9\-/\.]+"
r"|T\d{2}\-\d{6,}"
r"|HM\d{2}[A-Z\-]*"
r"|JM\d{3}[A-Z\.\-\d]*"
r"|PILOT\d*/?[A-Z0-9]*"
r")\b"
)
tests = [
"2.00 JEITCS12 TURBO TOUGH, 12MM X 40MM TCT (6MM PILOT) 12.75 25.50",
"10.00 JEICS17 TURBO STEEL, M2-AL CUTTER, 17MM X 1 inch 5.57 55.70",
"5.00 JEITCS16 TURBO TOUGH, 16MM X 40MM TCT (6MM PILOT) 12.90 64.50",
"30.00 JEITCS14-P1 TURBO STEEL, 14MM X 1 inch 5.13 153.90",
"100.00 JEIPILOT1 PILOT PIN 1.40 140.00",
"TCT INVOICE 2.00 JEITCS12 25.50", # Header + line item
]
for t in tests:
m = pair_re.search(t)
if m:
print("OK qty=%s code=%s | %s" % (m.group(1), m.group(2), t[:70]))
else:
print("NO | %s" % t[:70])