> 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/chinese/guan-li-yu-she-zhi/settings/global-settings/document-types/regex/creating-a-regex-pattern.md).

# 创建正则表达式模式

## 要创建能够正确匹配所需数据的新正则表达式模式，请按照以下步骤操作：

**明确目标：**

* 首先，明确要提取哪种类型的数据，以及这些数据出现的上下文。
* 了解要捕获数据的结构和格式。

**识别模式：**

* 分析示例数据，找出要提取数据的典型模式或结构，同时考虑可能的变化和边缘情况。

**使用正则表达式运算符：**

* 选择适当的正则表达式运算符和结构来描述已识别的模式。
* 这些内容包括元字符，例如

  ´.´（任意字符）、´\*´（任意数量）、´+´（至少出现一次）、´?（出现零次或一次），以及字符类，例如´\d´（数字字符）、´\w´（字母数字字符）和´\（空格）。

**测试模式：**

* 使用测试数据，确保正则表达式模式能够正确捕获所需数据，并考虑可能的边缘情况。
* 可以使用在线正则表达式测试工具或专用软件工具进行测试。

**优化模式：**

* 检查正则表达式模式，并在必要时进行优化，使其更加精确、高效。
* 例如，避免使用过于宽泛、可能返回过多非预期匹配项的模式。

**记录模式：**

* 记录正则表达式模式，包括其用途、工作方式和可能的限制。
* 这样其他开发人员就更容易使用和理解该模式。

**实现模式：**

* 将正则表达式模式集成到应用程序或脚本中，以提取所需数据并进行后续处理。

## 创建有效正则表达式模式的其他建议：

* 使用分组 '( )' 定义子模式并控制其重复次数。
* 在模式中考虑特殊情况和限制条件。
* 指定足够具体，但不要过于严格，以便匹配预期数据的各种变化。
* 在相关场景下区分大小写；适当时使用 i 修饰符忽略大小写。
* 尝试使用不同的模式并定期检查结果，确保模式正常工作。


---

# 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/chinese/guan-li-yu-she-zhi/settings/global-settings/document-types/regex/creating-a-regex-pattern.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.
