> For the complete documentation index, see [llms.txt](https://docs.gpmautomate.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gpmautomate.com/automate-en/action-guides/text-and-number/regex.md).

# Regex

Regex (Regular Expression) is like a magnifying glass that helps you precisely find a hidden piece of text within a large document, or like a filter that allows you to retain the exact data format you need (such as phone numbers, emails, OTP codes) while discarding unnecessary surrounding text.

#### Configuration parameters:

* Text: The raw input text that needs to be filtered (or the variable containing the text).
* Regex: The filter code/syntax used to define the structure of the string to be extracted.
* Output variable: The name of the variable that stores the result after successful filtering.

#### Real-world example: Extracting OTP code from Email content

When you use the action to read an email, the system will return the entire text content of a lengthy email. Your task is to extract the correct 6-digit OTP code contained within it.

Suppose the input Text received is:

> "Your GPM Automate verification code is 834912. Please do not share this code with anyone, the code is valid for 5 minutes."

To filter out the 6-digit OTP, you configure the Regex action as follows:

* Text: Pass in the above text (or the variable containing the email content).
* Regex: Enter `\d{6}` *(this is the regex syntax representing 6 consecutive numeric characters)*.
* Output variable: Enter the name of the variable to store (e.g., `$otpCode`).

Result: The "filter" Regex will scan through the text, ignoring all the Vietnamese text and accurately retaining the string `834912` to assign to the variable `$otpCode`.

> 💡 Tip: Does the Regex syntax seem complicated and hard to remember? Don't worry, you don't need to memorize it. Just open AI tools (like ChatGPT, DeepSeek, Gemini...) and ask directly in natural language, for example: *"Write me a regex to filter out 6 consecutive digits"* or *"Write regex to get the string between 'Your code is:' and the period"*. AI will generate the exact code for you to simply copy-paste into the configuration field of GPM Automate.

<figure><img src="/files/7OgmkRgAjyXesvpn6PRr" 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 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.gpmautomate.com/automate-en/action-guides/text-and-number/regex.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.
