> For the complete documentation index, see [llms.txt](https://docs.docbits.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.docbits.com/administration-and-setup/setup/document-training/training-line-fields-table-training/improving-table-extraction-with-regex.md).

# Structuring and Improving Table Extraction in DocBits

Once a table is extracted and the initial column mapping is complete, you can enhance the quality and structure of the data using several built-in tools. This guide walks you through:

* Grouping rows
* Manual row selection
* Column mapping
* Header refinement using regex

These tools are especially helpful when dealing with complex or inconsistent document layouts.

### 1. Grouping Rows

Documents like invoices or order confirmations often contain table entries where one column (e.g., a description) spans multiple lines, while other columns (e.g., quantity or price) only use one line.

Take this German invoice example — the “Bezeichnung” (description) column spans multiple rows:

<figure><img src="https://578966019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FT2n2w4uDCJvv7CJ5zrdk%2Fuploads%2Fgit-blob-55e0e078a1b8254cf5a811303f74d46279782c11%2Fa-training-line-fields-table-training-advanced-settings-overflow-doc-en-20261006.png?alt=media" alt="German invoice table where the Bezeichnung (description) of each item spans several lines."><figcaption><p>A description column that spans several rows.</p></figcaption></figure>

Initially, DocBits extracts each row separately:

<figure><img src="https://578966019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FT2n2w4uDCJvv7CJ5zrdk%2Fuploads%2Fgit-blob-b541bfb88aba936c219f6357956cd22ee0ec7430%2Fa-training-line-fields-table-training-improving-table-extraction-with-regex-initial-extraction-en-20261006.png?alt=media" alt="Extracted table where every text line of the description became its own row."><figcaption><p>DocBits first extracts each row separately.</p></figcaption></figure>

You can then **group rows based on a column**, such as “Position.” This merges related lines into a single, structured entry:

<figure><img src="https://578966019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FT2n2w4uDCJvv7CJ5zrdk%2Fuploads%2Fgit-blob-95e6018c656582358ba1ea05e230c97ace018a95%2Fa-training-line-fields-table-training-advanced-settings-reverse-result-en-20261006.png?alt=media" alt="Extracted table with the description lines merged into one entry per position."><figcaption><p>After grouping by Position the related lines form one entry.</p></figcaption></figure>

### 2. Manual Row Selection

In some cases, the text on a document is spread across several columns in a single row, making it difficult to assign automatically.

Here’s an example where the “PRAEF” line overlaps **Bezeichnung**, **Menge**, **ME**, and **Preis in EUR**:

<figure><img src="https://578966019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FT2n2w4uDCJvv7CJ5zrdk%2Fuploads%2Fgit-blob-44469c0d22d7f2b63d80e281cde83e00d881989f%2Fa-training-line-fields-table-training-improving-table-extraction-with-regex-row-misalignment-en-20261006.png?alt=media" alt="Invoice table with a PRAEF line whose text runs across several columns."><figcaption><p>A PRAEF line that does not align with the column structure.</p></figcaption></figure>

#### 🔧 How to Manually Assign Values:

1. **Enable Training Mode**

   <figure><img src="https://578966019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FT2n2w4uDCJvv7CJ5zrdk%2Fuploads%2Fgit-blob-3539f68488150838fc1f0230aafc551104433e6a%2Fa-training-line-fields-table-training-improving-table-extraction-with-regex-training-mode-en-20261006.png?alt=media" alt="Table extraction screen with Training Mode switched on."><figcaption><p>Training Mode enabled.</p></figcaption></figure>
2. **Activate Row Edit Mode**

   <figure><img src="https://578966019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FT2n2w4uDCJvv7CJ5zrdk%2Fuploads%2Fgit-blob-25fbdcd1b6b9588ee1fe41d613f5b1b14f2d5dfa%2Fa-training-line-fields-table-training-improving-table-extraction-with-regex-row-edit-mode-en-20261006.png?alt=media" alt="Table extraction screen with the Row data edit mode toggle switched on and its tooltip shown."><figcaption><p>Row edit mode activated.</p></figcaption></figure>
3. **Select and Map Text**\
   Click the correct piece of text and assign it to a **blue** column header.

   <figure><img src="https://578966019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FT2n2w4uDCJvv7CJ5zrdk%2Fuploads%2Fgit-blob-0084239bb65ccca75c2af62a95d85c8f22466346%2Fa-training-line-fields-table-training-improving-table-extraction-with-regex-editable-columns-en-20261006.png?alt=media" alt="Extracted table in row edit mode with the blue, not yet filled column headers that can be assigned manually."><figcaption><p>Blue column headers can be filled manually.</p></figcaption></figure>

> Note: Violet-colored columns are already system-mapped and cannot be manually edited.

### 3. Mapping Columns

Column mapping links your extracted data to the expected column headers, ensuring consistency and exportability.

To map or remap a column:

1. Click the column header in the extraction view.
2. Choose the correct target column from the dropdown.

<figure><img src="https://578966019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FT2n2w4uDCJvv7CJ5zrdk%2Fuploads%2Fgit-blob-5f1cb650d4f7035926122fcce9c71260bce26376%2Fa-training-line-fields-table-training-improving-table-extraction-with-regex-mapping-dropdown-en-20261006.png?alt=media" alt="Extracted table with the column header dropdown open listing the target columns Description, Item Number, Net amount, Position, Quantity, Total amount, Unit and Unit price."><figcaption><p>Choose the target column in the header dropdown.</p></figcaption></figure>

You can adjust the mapping as often as needed.

### 4. Extract From Above / Below

Some documents are structured in a way where relevant table values don't appear on the same row as other data. In these cases, DocBits allows you to control **where the data should be extracted from**:

* **Extract from Above**: Use this when the value for the current row appears **in the line above**.
* **Extract from Below**: Use this when the value appears **in the line beneath** the current row.

**Where to Find It**

1. Enter **Training Mode**.
2. Click the three dots (⋯) on a column header.
3. Under the **"Extract From"** option, choose `Above` or `Below` depending on the document layout.

### 5. Amount Format

Some columns, such as **Quantity** or **Unit Price**, contain numeric or date values that may follow different formatting conventions depending on the document's origin or locale. DocBits allows you to specify the format these values should follow to ensure accurate extraction and interpretation.

**Amount Format Options:**

* Define the expected number or date format for the column, such as US (MM/DD/YYYY, decimal with dot), Poland (DD.MM.YYYY, decimal with comma), Germany, and others.
* This helps DocBits correctly parse and standardize values even if the document uses a different regional format.

**Where to Find It**

1. Enter **Training Mode**.
2. Click the three dots (⋯) on the header of a supported column (e.g., Quantity, Unit Price).
3. Under the **Amount Format** option, select the desired format matching your document's locale.

### 6. Improving Table Extraction with Regex

### **What It Does**

This feature allows you to define a regex for each table header, improving extraction accuracy and ensuring correct results.

### **How to Use It**

1. Open a document from the supplier for which you want to define a regex.
2. Navigate to the **Table Extraction** view.\\

   <figure><img src="https://578966019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FT2n2w4uDCJvv7CJ5zrdk%2Fuploads%2Fgit-blob-37fb817b2a2227ae16b2df1af50920678b668758%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
3. Enable **Training Mode**.
4. Select the table header you want to refine, then choose **Regex**.\\

   <figure><img src="https://578966019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FT2n2w4uDCJvv7CJ5zrdk%2Fuploads%2Fgit-blob-f4b4f39558c91601bdd7df798ef07ca8b9138cea%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
5. A popup will appear where you can enter and define your regex.\\

   <figure><img src="https://578966019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FT2n2w4uDCJvv7CJ5zrdk%2Fuploads%2Fgit-blob-77b8eef3a494a78c76639f08123edc109c91985e%2FiScreen%20Shoter%20-%20Google%20Chrome%20-%20250303135020.jpg?alt=media" alt=""><figcaption></figcaption></figure>
6. Click **Validate** to check the regex, then **Save Changes** to apply it.\\

   <figure><img src="https://578966019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FT2n2w4uDCJvv7CJ5zrdk%2Fuploads%2Fgit-blob-3d8d1e676140c279c30d39017040bfc837d59266%2FiScreen%20Shoter%20-%20Google%20Chrome%20-%20250303135153.jpg?alt=media" alt=""><figcaption></figcaption></figure>
7. **Save the rule and confirm** to apply the changes.

### When to Use Each Feature

Use these tools to increase extraction accuracy and reduce manual work:

* **Grouping**: When a description or any column spans multiple rows and needs to be combined for clarity.
* **Manual Row Selection**: When rows aren’t structured cleanly, and parts of the content fall into the wrong columns.
* **Column Mapping**: When the automatically detected column names don’t match your structure or need refinement.
* **Regex Rules**: When table headers vary slightly across documents from the same supplier or OCR introduces inconsistencies.


---

# 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://docs.docbits.com/administration-and-setup/setup/document-training/training-line-fields-table-training/improving-table-extraction-with-regex.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.
