OCR Extract Pattern
OCR Extract Pattern
Section titled “OCR Extract Pattern”Type: ocr-extract-pattern · Package: OCR Activities v1.2.5 · Output: Dictionary<string, string>
Since: v1.2.0
Combines OCR + regular expressions in one step: it recognizes the text of an image and, on that text, applies a set of patterns (regex) to extract specific fields. It returns a dictionary { field: value }. It is the most direct way to get structured data out of a scanned document (invoice number, date, total).
How it works
Section titled “How it works”Runs OCR on the image (once) and, on the resulting text, evaluates each pattern of the patterns dictionary:
- It takes the first match of each pattern in the whole text.
- If the pattern has a capture group
(...), the value is what the first group captures; otherwise, the whole match. - If the pattern does not match (or is empty), the field gets empty text
"". - Patterns are case-sensitive; to ignore case, start the pattern with
(?i).
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | — | Path to the image file (.png, .jpg, .bmp, .tiff). |
patterns | Dictionary | — | Dictionary fieldName → regex pattern. Use a capture group to extract only the value. Values can be expressions. |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
language | string | "eng" | Text language: Tesseract code (eng, spa, eng+spa) or regional tag (es-CO). See language. |
preprocess | string | "none" | Prior cleanup: none · auto · deskew · binarize. See preprocessing. |
Output
Section titled “Output”Returns a Dictionary<string, string> with one key per pattern in patterns (always all of them) and its text value: the data found, or "" if there was no match. Check for empty fields before using them.
Example
Section titled “Example”Extract the number, date and total of a scanned invoice:
OCR Extract Pattern path = invoicePath language = "eng" preprocess = "auto" patterns = { "number": "INV-(\d+)", "date": "Date:\s*(\d{4}-\d{2}-\d{2})", "total": "Total:\s*\$?([\d.,]+)" } → output: data
If condition = isEmpty(data["total"]) └─ then: Throw message = "Could not read the invoice total"Log message = "Invoice " + data["number"] + " — Total " + data["total"]Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
'patterns' is required. | patterns is missing. |
'patterns' must be a Dictionary<string, string> mapping field names to regex patterns. | patterns is not a { field: pattern } object (for example, a list or a text). |
Invalid regex for field '…': … | That field’s pattern has a syntax error (unclosed parenthesis, unescaped \…). |
File not found. | The path does not exist on the robot’s machine. |
Tesseract language '…' not found at '…'. Available: [eng, spa]. | The language code is not installed. |
Related activities
Section titled “Related activities”- OCR Recognize File — get the text and extract it yourself with
regexFind. - OCR Extract Form Fields — extract by position instead of by pattern.