Files
2026-07-12 10:17:17 -04:00

4.0 KiB

OCR Regex Catalog — Appointment Parsing

Full extraction patterns from the ShopProQuote production parser, with OCR corruption variants and test cases.

Structured Field Patterns

Field Regex Notes
Phone \(?\d{3}\)?[\s.\-]*\d{3}[\s.\-]*\d{4} Forgiving of (xxx), xxx-xxx, xxx.xxx
VIN \b[A-HJ-NPR-Z0-9OIQ]{17}\b/i Accepts O→0, I→1, Q→0 OCR errors
Email \b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b Extract BEFORE VIN to prevent false matches
Date `\b(?:\d{4}[/-.]\d{1,2}[/-.]\d{1,2} \d{1,2}[/]\d{1,2}(?:[/]\d{4})?
Time `\b(\d{1,2}):(\d{2})\s*(AM PM)?\b
Duration `\b(\d+(?:.\d+)?)\s*(?:min minutes?
OP Code \[([A-Z0-9\-:]+)\] [REP], [MA10], [23-046:6MX00]
Vehicle (\d{4})\s+([A-Za-z]+)\s+([A-Za-z0-9\-]+) 2023 Honda RIDGELINE
Vehicle fallback (\d{4})\s+([A-Za-z]+) 2023 Honda
Row anchor `(\d{1,2}):(\d{2})\s*(AM PM)\s+(\d+(?:.\d+)?)\s*hrs?`

Known Makes

ford|chevy|chevrolet|toyota|honda|nissan|bmw|mercedes|audi|dodge|jeep|gmc|ram|hyundai|kia|subaru|mazda|vw|volkswagen|lexus|acura|infiniti|cadillac|buick|chrysler|lincoln|tesla|volvo

Advisor/Noise Stripping Patterns

Known Advisor Names

Rrahman Grajqevci, Rrshman, Grajqevci, Grokevel

OCR Corruption Variants

eE 3 zoom, Eee om 3 gem, eE\s*3\s*zoom, Eee\s*om\s*3\s*gem

Junk Tokens

RO, VIN, os, b=

Header Metadata (strip before parsing)

/^(Monday|Tuesday|...|Sunday)\s+[A-Z][a-z]{2}\s+\d{1,2}/i  // "Wednesday Jun 18, 2025"
/^(Advisor|Refresh|Weekly|Daily)(\s|$)/i                     // "Weekly", "Advisor"

Service Extraction Rule

// Stop at newline — critical to prevent vehicle info absorption
var svcRe = new RegExp('\\[' + opCode + '\\]\\s*([^\\n\\[]*)', 'i');

Wrong (captures vehicle on next line):

var svcRe = new RegExp('\\[' + opCode + '\\]\\s*([^\\[]*)', 'i');

Block Splitting Hierarchy

  1. Row-anchor split (preferred): Find Time+Duration patterns → split at each boundary
  2. Blank-line fallback: t.split(/\n\s*\n/) when < 2 anchors found
  3. Table fallback: Uniform word counts across lines → treat each line as a record

VIN OCR Fix

function fixVin(v) {
    return v.toUpperCase().replace(/O/g,'0').replace(/I/g,'1').replace(/Q/g,'0');
}

Cross-Block Name Carry

// Return value from parseOne() is nextName — passes between blocks
if (appt.serviceType) {
    var tn = appt.serviceType.match(/\s+([A-Z]{2,}(?:\s+[A-Z]{2,}){1,2})\s*$/);
    if (tn && tn[1].length > 3) {
        appt.serviceType = appt.serviceType.substring(0, appt.serviceType.length - tn[0].length).trim();
        nextName = tn[1];
    }
}
return nextName; // fed as carryName to next block

Test Cases

T5: 3-appointment screenshot with blank lines

9:00AM 0.5 hrs RO Gary Bowers (865) 335-3874 Rrahman Grajqevci [REP] Tailgate wiring harness connector replacement garyb9623@gmail.com
2023 Honda RIDGELINE VIN SEPYK3F70PB011523

10:30AM 1.0 hrs RO HITESHKUMAR PATEL 865-235-0156 Rrahman Grajqevci [23-046:6MX00] Oil change and tire rotation
2013 Honda ODYSSEY VIN SENRLEHB9PB042710

11:45AM 0.5 hrs RO STEPHEN LOWERY 865-384-6984 Rrahman Grajqevci [MA10] Replace front brake pads
2013 Honda CROSSTOUR VIN SJ6TF1HS4DL001541

T6: Row-anchor (no blank lines, Monday header)

Wednesday Jun 18, 2025  Weekly  Advisor  Refresh
9:00AM 0.5 hrs RO Gary Bowers (865) 335-3874 Rrahman Grajqevci [REP] Tailgate wiring
2023 Honda RIDGELINE VIN 5FPYK3F70PB011523 garyb9623@gmail.com
10:30AM 1.0 hrs RO HITESHKUMAR PATEL 865-235-0156 Rrahman Grajqevci [23-046:6MX00] Oil change
2013 Honda ODYSSEY VIN SENRLEHB9PB042710
11:45AM 0.5 hrs RO STEPHEN LOWERY 865-384-6984 Rrahman Grajqevci [MA10] Brake pads
2013 Honda CROSSTOUR VIN SJ6TF1HS4DL001541