Skip to content

OCR Extract Pattern

Type: ocr-extract-pattern  ·  Package: OCR Activities v1.0.0  ·  Output: Dictionary

It combines OCR + regular expressions in a single step: it recognizes the text of an image and, on that text, applies a set of patterns (regex) to extract specific fields. Returns a { campo: valor } dictionary. It is the most direct way to extract structured data from a scanned document (invoice number, date, total).

Runs OCR on the image and, on the resulting text, evaluates each pattern in the patterns dictionary. For each pattern that matches, add nombreCampo → valor to the result. Use a capture group in the regex to extract only the part you are interested in.

ParameterEditorDescription
pathexpressionImage file path.
patternsobjetonombreCampo → patrón regex Dictionary. Use a capture group to extract the value.
ParameterEditorDescription
languageexpressionLanguage code: eng (def.) · spa · eng+spa.
preprocessexpressionLimpieza previa: none (def.) · auto · deskew · binarize.

Returns a Dictionary with a pair for each pattern that was matched.

Extract number, date and total from a scanned invoice:

OCR Extract Pattern
path = = rutaFactura
language = "spa"
preprocess = "auto"
patterns = {
"numero": "FAC-(\d+)",
"fecha": "Fecha:\s*(\d{4}-\d{2}-\d{2})",
"total": "Total:\s*\$?([\d.,]+)"
}
→ output: datos
Log message = = "Factura " + datos["numero"] + " — Total " + datos["total"]