> 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/huong-dan-cac-action/text-and-number/regex.md).

# Regex

Regex (Regular Expression) giống như một chiếc kính lúp giúp bạn soi tìm chính xác một đoạn text ẩn nấp trong một văn bản lớn, hoặc như một chiếc lưới lọc giúp bạn giữ lại đúng định dạng dữ liệu mình cần (như số điện thoại, email, mã OTP) và gạt bỏ đi những phần chữ thừa thãi xung quanh.

🎥 Xem thêm video hướng dẫn: [Tại đây](https://youtu.be/nlEQsaxawt4).

#### Tham số cấu hình:

* Text: Văn bản thô đầu vào cần lọc dữ liệu (hoặc biến chứa đoạn văn bản).
* Regex: Đoạn mã/cú pháp bộ lọc dùng để định hình cấu trúc chuỗi cần lấy.
* Output variable: Tên biến lưu kết quả sau khi lọc thành công.

#### Ví dụ thực tế: Trích xuất mã OTP từ nội dung Email

Khi bạn dùng hành động đọc thư điện tử, hệ thống sẽ trả về toàn bộ nội dung text của Email dài loằng ngoằng. Nhiệm vụ của bạn là phải nhặt ra đúng mã OTP gồm 6 chữ số nằm trong đó.

Giả sử đoạn Text đầu vào nhận được là:

> "Mã xác minh GPM Automate của bạn là 834912. Vui lòng không chia sẻ mã này cho bất kỳ ai, mã có hiệu lực trong 5 phút."

Để lọc lấy 6 số OTP, bạn cấu hình hành động Regex như sau:

* Text: Truyền vào đoạn văn bản trên (hoặc biến chứa nội dung email).
* Regex: Điền là `\d{6}` *(đây là cú pháp regex đại diện cho 6 ký tự số liên tiếp)*.
* Output variable: Điền tên biến cần lưu (Ví dụ: `$otpCode`).

Kết quả: Chiếc "lưới lọc" Regex sẽ quét qua văn bản, bỏ qua toàn bộ phần chữ tiếng Việt và giữ lại chính xác chuỗi `834912` để gán vào biến `$otpCode`.

> 💡 Mẹo nhỏ: Cú pháp Regex trông có vẻ loằng ngoằng và khó nhớ? Đừng lo, bạn không cần phải tự học thuộc lòng làm gì cho đau đầu. Hãy mở các công cụ AI (như ChatGPT, DeepSeek, Gemini...) và hỏi trực tiếp bằng ngôn ngữ tự nhiên, ví dụ: *"Viết cho tao đoạn regex để lọc lấy 6 số liên tiếp"* hoặc *"Viết regex lấy chuỗi nằm giữa chữ 'Mã của bạn là:' và dấu chấm"*. AI sẽ sinh ra đoạn mã chính xác để bạn chỉ việc copy-paste vào ô cấu hình của GPM Automate.

<figure><img src="/files/4AjUcMsKZCtbbaJcJToO" 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/huong-dan-cac-action/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.
