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