> 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-inside-the-parentheses.md).

# 括号内的正则表达式

[正则表达式](/brand/zh/what-would-you-like-to-learn-about/platform-features/promo-codes/regular-expression/regex-explained.md) (或正则表达式) 是一种代码，当你想将上传的商品 SKU、分类或促销码中的一部分字符，与通过转化传递给 impact.com 的值进行匹配时，可以使用它。你可以将正则表达式与 impact.com 的匹配表达式工具结合使用，识别你希望以不同方式支付佣金的商品 SKU、分类或促销码。

#### 在括号内

通过将正则表达式的一部分放在括号内，你可以将该部分正则表达式组合在一起。然后，匹配表达式工具可以提取你放在括号之间的值，并在你提供的对应例外列表项中查找匹配项。你添加到例外列表中的项目应与括号中的正则表达式完全匹配，这样该正则表达式 [括号外](/brand/zh/what-would-you-like-to-learn-about/platform-features/promo-codes/regular-expression/regex-outside-the-parentheses.md) 就可以应用于整个列表。

#### 示例场景

你的品牌， *ACME Smile*，希望在客户购买任何牙科产品时向合作伙伴支付 5%。 *ACME Smile* 并没有涵盖所有牙科产品的完整 SKU 清单，因为你的品牌一直在下架产品并新增产品。不过，你知道所有牙科产品 SKU 都以 TOOTH、SMILE 或 SHINE 开头（例如 `SHINE98763`, `SMILE987abc`, `TOOTH65abc64`).

因为所有牙科 SKU 都以 TOOTH、SMILE 或 SHINE 开头，因此你可以为牙科产品 SKU 大致设置一个正则表达式，并使用匹配表达式工具在不完整的 SKU 例外列表中查找匹配项，如以下部分所示。

{% stepper %}
{% step %}

### 步骤 1：创建 SKU 列表

1. 从顶部导航栏中，选择 ![](https://1186853034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwMLlMoFBtKJa8ptd3zaw%2Fuploads%2F210dEQa93qyQgoJDkieL%2FUser%20profile.svg?alt=media\&token=f84c5b17-fae4-4a30-990a-9de5e57a150b) **\[用户资料] → 设置**.
2. 在右侧，在……下方 *异常列表* 部分下，选择 [**SKU**](https://app.impact.com/secure/advertiser/campaign/itemlist/view-skuitemlist-flow.ihtml).
3. 选择 **添加新的 SKU 列表**.
4. 输入一个 **列表名称**.
5. 选择 **事件类型** 要与此 SKU 列表关联的内容。
   {% endstep %}

{% step %}

### 步骤 2：设置正则表达式

1. 选择 **显示高级设置** 并在其中输入你的正则表达式 **匹配表达式** 字段中。
   * 在括号内，仅添加你想匹配的值：
     * 添加我们已知牙科 SKU 开头的 3 个字符串，并用正则表达式字符分隔 `|` ，这表示“或”。
   * 在括号外，添加任何有助于细化匹配的正则表达式：
     * 添加正则表达式字符 `^` 在左括号之前，以断言该位置位于行首，确保前面没有任何字符。
     * 添加正则表达式字符 `.` 在右括号之后，用于匹配后续任何字符（例如数字、字母、连字符），但不包括换行符。
     * 添加正则表达式字符 `*` 在句点之后，查找任意数量的匹配项（即，0 到无限多个匹配项之间）。
   * 最终表达式应为 `^(TOOTH|SMILE|SHINE).*`.
2. 选择 **保存并添加项目**.<br>

<div data-with-frame="true"><figure><img src="https://1186853034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwMLlMoFBtKJa8ptd3zaw%2Fuploads%2FWFAYx47NL9zXEA7EqkOt%2Fimage.png?alt=media&amp;token=ff38cad6-a0c1-4c00-b39d-36025dd0d053" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

### 步骤 3：添加例外列表项

1. 以 2 种方式中的 1 种列出要匹配的值：
   * **手动添加项目** 通过在中输入 TOOTH、SMILE 和 SHINE *Sku* 字段。<br>

     <div data-with-frame="true"><figure><img src="https://1186853034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwMLlMoFBtKJa8ptd3zaw%2Fuploads%2FoH6QfzDRJSsLdiFFuhiG%2FUntitled%20design%20(29).png?alt=media&amp;token=ecf9885b-292b-4651-9b56-df904665a10e" alt="" width="375"><figcaption></figcaption></figure></div>
   * 或者， **上传 CSV 或 Excel 文件** 通过在下方列出 TOOTH、SMILE 和 SHINE *SKU* 列。

     * 请参阅 [创建 SKU 异常列表](/brand/zh/what-would-you-like-to-learn-about/account-administration/program-settings/exception-lists/create-sku-exception-lists.md) 以了解更多信息。

     <div data-with-frame="true"><figure><img src="https://1186853034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwMLlMoFBtKJa8ptd3zaw%2Fuploads%2FqngJxT1772eJGcigeZMu%2FUntitled%20design%20(30).png?alt=media&amp;token=c030c1ca-d821-43a8-b304-558c6e47ab7d" alt="" width="374"><figcaption></figcaption></figure></div>
2. 选择 **保存**.
   * 你会在上看到新的 SKU 列表 *SKU 列表* 界面中进行设置。
     {% endstep %}
     {% endstepper %}

#### 接下来呢？

既然你已经设置了正则表达式匹配表达式并添加了这 3 个 SKU 列表项，所有 *ACME Smile*的未来牙科产品（假设它们的 SKU 也以 TOOTH、SMILE 或 SHINE 开头）都将作为例外列表的一部分进行匹配。任何与该正则表达式匹配的传入转化都会被标记为例外列表的一部分，并相应应用合约规则。

现在你可以添加规则到 *ACME Smile*的模板条款中，例如当这些 SKU 出现时，每笔订单支付 5%。参见 [为分类、SKU 或促销码例外列表设置支付规则](/brand/zh/what-would-you-like-to-learn-about/account-administration/program-settings/exception-lists/set-payout-rules-for-exception-lists.md) 了解更多详情。


---

# 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-inside-the-parentheses.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.
