> For the complete documentation index, see [llms.txt](https://help.impact.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.impact.com/brand/zh/what-would-you-like-to-learn-about/platform-features/promo-codes/regular-expression/regex-explained.md).

# 正则表达式说明

Regex（或正则表达式）是一种可用于匹配通用文本的代码，在匹配促销代码时非常有用。Regex 是区分大小写的，因此请务必按与你的促销代码大小写匹配的方式设置你的正则表达式。

* 正则表达式和促销代码主要有三种逻辑情况： `以...开头`, `以...结尾`，以及 `包含`.
* 在这个示例中，我们促销代码的基础是 `SUMMER`.

{% tabs %}
{% tab title="以...开头" %}
你已向合作伙伴发放了一系列夏季促销代码， `SUMMER20OFF`, `SUMMER10`，以及 `SUMMER25`。我们想把它们全部匹配出来，以便给合作伙伴记功，应该怎么做？我们会使用 `以...开头` 逻辑。只需在基础促销代码末尾添加一个句点和一个星号。

正则表达式应当正好是 `^(SUMMER).*`

这将自动匹配任何以 `SUMMER` 开头并以其他任意字符结尾的促销代码。任何不以 `SUMMER` 开头的代码都不会被匹配。
{% endtab %}

{% tab title="以...结尾" %}
你已向合作伙伴发放了一系列夏季促销代码， `20OFFSUMMER`, `10SUMMER`，以及 `25SUMMER` 其中促销代码始终以 `SUMMER`结尾。我们该如何匹配它们？我们会使用 `以...结尾` 逻辑。只需在基础促销代码开头添加一个句点和一个星号，并添加一个 $ 来指定字符串锚点。

正则表达式应当正好是 `^.*(SUMMER)$`

这将自动匹配任何以其他字符开头并以 `SUMMER`结尾的促销代码。任何不以 `SUMMER` 开头的代码都不会被匹配。
{% endtab %}

{% tab title="包含" %}
你已向合作伙伴发放了一系列夏季促销代码， `20SUMMER`, `SUMMER20OFF`，以及 `EXTRASUMMER10`，其中 `SUMMER` 出现在代码中的某处。我们会使用 `包含` 逻辑。添加 `.*` 在基础促销代码前后，并将表达式包裹在 ^ 和 $ 锚点中。

正则表达式应当正好是 `^.*(SUMMER).*$`

此正则表达式匹配包含 `SUMMER` 的促销代码，位置可以在代码中的任意地方。任何不包含 `SUMMER` 开头的代码都不会被匹配。
{% endtab %}
{% endtabs %}

对于更复杂的表达式，请联系你的 CSM 或 [联系支持团队](https://app.impact.com/support/portal.ihtml?createTicket=true\&accountType=ADVERTISER) 寻求帮助。

{% hint style="success" %}
**注意：** 你可以通过添加 `(?i)` 在 `^` 到你的正则表达式中来移除大小写敏感性。
{% endhint %}

## 示例

```programlisting
^(?i)(SUMMER).*
```


---

# 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://help.impact.com/brand/zh/what-would-you-like-to-learn-about/platform-features/promo-codes/regular-expression/regex-explained.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.
