> 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，或 Regular Expression）是一种可用于匹配通用文本的代码，在匹配促销码时非常有用。正则表达式区分大小写，因此请务必根据与你的促销码匹配的大小写来设置你的正则表达式。

* 正则表达式和促销码主要有两种逻辑情况——`以……开头` 和 `以……结尾`.
* 在这个示例中，我们的促销码基础部分是 `SUMMER`.

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

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

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

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

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

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

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

{% hint style="info" %}
**注意：** 你可以通过添加来移除正则表达式的大小写敏感性 `(?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 dynamically by asking a question.

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

```
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>
```

The question should be specific, self-contained, and written in natural language.
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.
