# 正则表达式详解

正则表达式（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: 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/nin-xiang-liao-jie-shen-me/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.
