> 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）是一种代码，可用于匹配一般情况下的文本，在匹配促销码时非常有用。正则表达式区分大小写，因此请确保正则表达式中的大小写与促销码一致。

* 正则表达式匹配促销码主要有三种逻辑情况： `starts with`, `ends with`，以及 `contains`.
* 在本例中，我们促销码的基础部分是 `SUMMER`.

{% tabs %}
{% tab title="以……开头" %}
你向合作伙伴发放了一系列夏季促销码： `SUMMER20OFF`, `SUMMER10`和 `SUMMER25`。我们希望匹配所有这些促销码，以便为合作伙伴记账。该怎么做？可以使用 `starts with` 逻辑。只需在基础促销码末尾添加一个句点和一个星号。

正则表达式应为 `^(SUMMER).*`

这样就会自动匹配所有以 `SUMMER` 开头、后面跟着任意字符的促销码。任何不以 `SUMMER` 开头的代码都不会匹配。
{% endtab %}

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

正则表达式应为 `^.*(SUMMER)$`

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

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

正则表达式应为 `^.*(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.
