> 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/settings/global-settings/document-types/regex/creating-a-regex-pattern.md).

# Creating a Regex Pattern

## To create a new Regex pattern that correctly matches the desired data, follow these steps:

**Define the goal:**

* First, clarify what type of data you want to extract and in what context it occurs.
* Understand the structure and format of the data you want to capture.

**Identify the pattern:**

* Analyze sample data to identify patterns or structures that are characteristic of the data you want to extract, keeping in mind possible variations and edge cases.

**Use Regex Operators:**

* Choose the appropriate Regex operators and constructs to describe the identified patterns.
* These include metacharacters such as

  ´.´ (any character), ´\*´ (any number), ´+´ (at least one occurrence), ´? (zero or one occurrence) and character classes such as ´\d´ (digital character), ´\w´ (alphanumeric character) and ´\ (space).

**Test the pattern:**

* Use test data to make sure your regex pattern correctly captures the desired data while taking into account possible edge cases.
* Use online regex testers or special software tools to do this.

**Optimize the pattern:**

* Check your regex pattern and optimize it if necessary to make it more precise and efficient.
* For example, avoid patterns that are too general and could return too many unwanted matches.

**Document the pattern:**

* Document your regex pattern, including its purposes, how it works and possible limitations.
* This will make it easier for other developers to use and understand the pattern.

**Implement the pattern:**

* Integrate your regex pattern into your application or script to extract and further process the desired data.

## Some additional tips for creating an effective regex pattern:

* Use groupings '( )' to define subpatterns and control their repetition.
* Consider special cases and constraints in your pattern.
* Be specific but not too restrictive to capture variations of the expected data.
* Be case sensitive when relevant and use the i modifier for case independence when appropriate.
* Experiment with your pattern and check the results regularly to make sure it is working correctly.


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.docbits.com/administration-and-setup/settings/global-settings/document-types/regex/creating-a-regex-pattern.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
