> For the complete documentation index, see [llms.txt](https://help.nightfall.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.nightfall.ai/developer-api/key-concepts/scanning_features/pre_configured_detection_rules/scanning-images-for-patterns-using-custom-regex-detectors.md).

# Scanning Images for patterns using Custom Regex Detectors

\
Using regex to identify long patterns in images can be challenging because OCR systems. In such cases, even Nightfall may not achieve 100% character-by-character accuracy. To improve results, you must introduce higher levels of flexibility into your regex patterns to accommodate common OCR inconsistencies. Here are some typical OCR challenges to keep in mind:

* **Spell-check noise**: Spell-checking tools can add artifacts like red underlines, which may interfere with text recognition.
* **Character ambiguity**:
  * The digit 0 may be misinterpreted as the letter O (or vice versa), depending on the font.
  * The character l (lowercase L) may be read as the digit 1.
  * The letter B may appear as the digit 8.
* **Underscore handling**: An underscore (`_`) is sometimes interpreted as a space, particularly when spell-check artifacts are present.
* **Line wrapping**: OCR may introduce unexpected newlines when text wraps across multiple lines.
* **Periods and punctuation**: Spell-check artifacts or font issues may result in extraneous periods (`.`) or other punctuation being added to the output. En dash (–) and hyphens (`-`) may be  interchanged.

For reference, OCR tools like Tesseract typically achieve 85-98% character accuracy for similar input, and our system operates within a similar range. Given this, tuning your regex to be more forgiving (e.g., allowing for optional characters or slight variations) can significantly improve detection rates.

**Example Regex (original and loosened)**

original:     ATATT3xFfGF0\[A-Za-z0-9=\_\\-]\*\[=A-Za-z0-9]{9}<br>

loosened:  ATATT\[A-Za-z0-9\_\\-– @.\n=]\*\[A-Za-z0-9\_\\- @.\n]{7,11}

* shortened the literal match prefix
* excluded the the literal zero (`0`) from the prefix
* added period (`.`) and newline () chars
* relaxed the char length

<figure><img src="https://3789559529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDE6VZCJNhkLwvzLp4YDN%2Fuploads%2F6LEH4vpTLys80gZdNYIN%2Fimage.png?alt=media&amp;token=21fddf8e-477d-4d75-9ec7-53b5211fa243" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.nightfall.ai/developer-api/key-concepts/scanning_features/pre_configured_detection_rules/scanning-images-for-patterns-using-custom-regex-detectors.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
