> 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, and the optional `goal` 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>&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.
