Skip to content

Regex Anchor Refiner

A Regex Anchor is a page condition that needs no script. It searches the OCR text of the page for a .NET regular expression. When it finds a match, it votes for the subclass and moves a zone you drew so that the zone lines up with the match. Use it when a label or a form ID is always present but moves around the page, or when one exact string tells two subclasses apart.

At a glance

  • Runs On the server, on the Intuitive AI worker, for each page it is tested on
  • Language A .NET regular expression, no slashes
  • Configured in Intuitive AI app, subclass, Add Refiner: or Add Condition:, Regex Anchor
  • Returns 0 with no match; 0.5 plus half the OCR confidence of the matched text with a match
  • Best for Labels that move, form IDs, revision lines

How it runs

graph TD
  A["Page OCR text"] --> B[".NET regex, 5 second limit"]
  B -->|no match| Z["Confidence 0"]
  B -->|match| C["First match, or its first captured group"]
  C --> D["Zone moved onto the matched text"]
  D --> E["Confidence 0.5 to 1"]
  D --> F["OCR actions in the rule shift their zones"]
  1. The engine gets the OCR text of the whole page, not only the zone.
  2. It runs your pattern with .NET System.Text.RegularExpressions and a 5 second timeout. A timeout or a bad pattern raises "Error while matching regex" for the document.
  3. It uses the first match. If the pattern has capture groups and the M flag is not set, it uses the first group that captured text.
  4. It finds where that text is on the page. It moves the zone so that the zone's bottom-right corner lines up with the bottom-right corner of the matched text. It scales the zone to the page size and corrects for page rotation.
  5. The confidence is 0.5 + (OCR confidence of the matched text / 2). No match gives 0.

Other conditions and actions in the same rule can use the moved zone. An OCR action in the rule moves its own zone to follow any condition zone with a confidence above 0.5. A refiner's moved zone does not reach the rules: each rule gets its own state on each page.

Where you configure it

  1. Open the Intuitive AI app (permission: Use This App) and open a subclass.
  2. In a page refiner section, select Add Refiner: and pick Regex Anchor. In a page rule, use Add Condition: instead.
  3. Draw or select the zone the anchor controls. Draw it tight around the text the pattern matches on the model page.
  4. Enter the pattern in RegEx:. Open the flag menu (the / button) to set Regex Flags.

The condition is not configured until it has both a zone and a pattern ("This condition requires a regular expression.").

Configuration

The condition stores this object:

Regex Anchor configuration
{
  "ZoneId": "0b3e5f7a-1c2d-4e5f-8a9b-0c1d2e3f4a5b",
  "Regex": "Invoice\\s+Total",
  "Flags": ["i"],
  "Version": 2
}
Flag Effect
i (insensitive) Case-insensitive match. On by default for a new anchor.
x (ignore pattern whitespace) Spaces and # comments in the pattern are ignored
M (capture Match only) Use the whole match, not the first capture group
e (explicit capture) Only named groups capture. Ignored when M is set.

If you clear every flag, the match is case-sensitive.

.NET regex notes

The pattern is .NET syntax, not JavaScript syntax. The differences that matter:

  • Write the pattern without slashes: Invoice\s+Total, not /Invoice\s+Total/i. Set flags with the flag menu.
  • Named groups are (?<name>...). Lookbehind ((?<=...)) works.
  • Inline options work: (?i) turns on case-insensitive matching for the rest of the pattern.
  • \d matches any Unicode digit. Use [0-9] for ASCII digits only.
  • OCR text has line breaks between lines. Use \s+ between words, not a single space.

Examples of patterns

Goal Pattern
A label that moves Invoice\s+Total\s*:?
A form ID and revision, anchored on the revision date Form\s+PRM[-\s]?210\s*\(?\s*Rev[.,]?\s*([0-9]{2}\s*/\s*2024)
A label that OCR misreads INV[O0]ICE\s+N[O0o]\.?
A bounded value after a label Policy\s+Number\s*:?\s*([A-Z]{2}[0-9]{6,8})

In the second row, the capture group makes the zone line up with the revision date, not the whole line.

OCR action with a regex refiner

The OCR action (shown as "Extract from OCR Snippet") reads the text in a zone and writes it to the Index field you pick in Property:. Its optional RegEx: box keeps only the part of the zone text that matches.

Item Behavior
Pattern scope The zone text only
Timeout 5 seconds
Case Always case-insensitive. The x and e flags have no effect on this action.
Flags that work g (all matches, joined with no separator) and M (whole match). Without M, the text of every capture group that matched is joined, and the rest of the match is dropped.
No match The field is not written. The zone text goes to the Assist bucket key OcrInteractionAction_Value_<action id>.

The action also keeps the zone OCR for scripts. A Custom Action listed after it in the same rule can read it with state.OcrCache.Get("<Property name>"). See Clean a Zone Value and Write It to a Field.

Gotchas

Patterns that anchor in the wrong place, or never

  • The match is on the whole page. A label that appears twice (for example "Total" in a line-item table and in the footer) anchors to the first one. Make the pattern specific: Invoice\s+Total\s*:?.
  • OCR errors break literal text. OCR can read 0 as O or 1 as l. Allow both where it matters: INV[O0]ICE.
  • Catastrophic backtracking. Nested quantifiers such as (\w+\s*)+: can hit the 5 second timeout on a dense page. Prefer bounded patterns: \w{1,30}.
  • The zone lands in the wrong place. The zone's bottom-right corner moves to the bottom-right of the match (or of the first captured group). Draw the zone on the model page around exactly the text the pattern matches.
  • Check the real OCR text. In the subclass, use Show OCR Data to see the text the engine reads, and test your pattern against it.

Examples