# 匹配规则详解

## 匹配规则详解

在体验配信条件、页面组、转换、事件设置中，使用以下规则定义数据匹配条件。

## 包含

定义包含特定字符串的URL。例如，如果注册「`abc.com`」为「包含」，则以下URL将被包含在目标中。

```
https://abc.com/lp
https://abc.com/company
https://abc.com/company/contact
```

## 不包含

定义不包含特定字符串的URL。

例如，如果要定位除博客页面外的所有页面，请注册「`example.com/blog`」为「不包含」。

### **输入字段中有多个内容的情况**

如果包含任何内容，则排除在目标外。

例如，如果按如下设置，访问两个页面的用户（即使只访问其中一个）也将被排除在活动目标外。

仅输入子目录的情况也是相同的。

以下URL均无法匹配条件，因此不在目标范围内。

```
https://abc.com/company/login
https://abc.com/company/checkout
https://abc.com/company/campaign1
https://abc.com/company/login/checkout/campaign1
```

## 前向匹配

定义注册的字符串与URL开头匹配的URL。

当目标包含查询参数的URL时，通常使用此方法。

例如，假设当特定访问者(id=9982251615)访问时发行以下URL。

```
https://www.example.com/checkout.cgi?page=1&id=9982251615 
```

如果按前向匹配注册上述URL，则id=9982251615以外的用户访问不被定义为目标。

如果要在限制page=1的基础上定位所有用户ID，请按前向匹配注册以下URL。

```
https://www.example.com/checkout.cgi?page=1 
```

如果要在计测目标中包含除page=1以外的页面，请按前向匹配注册以下URL。

```
https://www.example.com/checkout.cgi?page
```

## 后向匹配

定义注册的字符串与URL末尾匹配的URL。

例如，如果按后向匹配注册「`/test/index.html`」，以下URL将被定义为目标。

```
http://www.example.com/s/test/index.html 
```

在这种情况下，前缀不同的以下URL也将被定义为目标。

```
http://www.123.com/s/test/index.html
```

但是，以下URL的末尾不是「/test/index.html」，因此不被定义为目标。

```
http://www.example.com/s/test/index.html?wore=xxx
```

## 完全匹配

定义与注册URL完全一致的URL作为目标。

## 正则表达式

正则表达式是一种用一种格式表示多个字符串的表达方式。

通过使用正则表达式，可以定义更灵活的条件。

### **正则表达式的语法**

实际正则表达式用于从大量数据中搜索与正则表达式模式匹配的字符串等情况。

要指定定义条件，需要使用特殊符号。

这些称为特殊字符或元字符，主要分为通配符、锚点和分组三类。

具体说明如下。

**通配符**

**锚点**

**分组**

**其他**

### 正则表达式常用组合

域名前缀完全匹配，末尾带有/或?参数的情况

```css
正则表达式：
^https:\/\/www.ptmind.com($|\/$|\/\?.*)

包含的URL：
https://www.ptmind.com
https://www.ptmind.com/
https://www.ptmind.com/?WT.mc_id=xxxx

不包含的URL：
https://www.ptmind.com/abc
```

要将包含http或https以及子域名的URL组合在一起的情况

```css
正则表达式：
^(http|https):\/\/(sh|bj|tj).ptmind.com

包含的URL：
http://sh.ptmind.com
http://bj.ptmind.com/abc
http://tj.ptmind.com
https://sh.ptmind.com
https://bj.ptmind.com/?WT.mc_id=xxxx
https://tj.ptmind.com

不包含的URL：
https://www.ptmind.com
```

要在同一子目录中组合的情况

```css
正则表达式：
^http:\/\/ptmind\.com\/price.*$

包含的URL：
http://ptmind.com/price/page
http://ptmind.com/price?sid=23fwe3r2&vid=345666
http://ptmind.com/price#top
http://ptmind.com/price

不包含的URL： ー
```

要将包含http或https、具有相同主域名的URL在同一子目录中组合的情况

```css
正则表达式：
^(http|https):\/\/[a-z0-9]*[.]*ptmind.com\/service\/mng_units\/lp03$

包含的URL：
http://www.ptmind.com/service/mng_units/lp03
https://www.ptmind.com/service/mng_units/lp03
http://ptmind.com/service/mng_units/lp03
http://a123.ptmind.com/service/mng_units/lp03
https://ptmind.com/service/mng_units/lp03

不包含的URL：ー
```

要将ID在指定范围内的URL组合在一起（从6984604到6984783）的情况

```css
正则表达式：
^http:\/\/ptmind.com\/detail\/id=6984([6][1-9][0-9]|[6][0][4-9]|[7][0-7][0-9]|[7][8][0-3])$

包含的URL：
http://ptmind.com/detail/id=6984604
http://ptmind.com/detail/id=6984783

不包含的URL：
http://ptmind.com/detail/id=6984784
http://ptmind.com/detail/id=6984603
```

#### 正则表达式验证工具

可以使用[这样的](/cn/faq/others/matching-rules.md)工具来确认正则表达式的书写是否正确。

※如有任何问题，请随时通过产品内聊天与我们联系。


---

# 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://helps.ptengine.com/cn/faq/others/matching-rules.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.
