> 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 区分大小写，因此请务必根据你的促销码的大小写设置你的正则表达式。

* Regex 和促销码主要有两种逻辑情况——`以……开头` 和 `以……结尾`.
* 在这个例子中，我们的促销码基础是 `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.
