

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 字串值比對
<a name="string-value-matching"></a>

透過將字串值與訊息屬性值或訊息內文屬性值相符來篩選訊息。在 JSON 政策中，字串值是以雙引號括住。您可以使用下列字串操作來比對訊息屬性或訊息內文屬性：

## 完全符合
<a name="string-exact-matching"></a>

政策屬性值符合一或多個訊息屬性值時，即完全相符。對於`String.Array`類型屬性，陣列中的每個元素都被視為單獨的字串，用於比對目的。

舉例下列政策屬性：

```
"customer_interests": ["rugby", "tennis"]
```

它符合以下訊息屬性：

```
"customer_interests": {"Type": "String", "Value": "rugby"}
```

```
"customer_interests": {"Type": "String", "Value": "tennis"}
```

```
"customer_interests": {"Type": "String.Array", "Value": "[\"rugby\", \"tennis\"]"}
```

它也符合以下訊息內文：

```
{
   "customer_interests": "rugby"
}
```

```
{
   "customer_interests": "tennis"
}
```

不過，它不符合下列訊息屬性：

```
"customer_interests": {"Type": "String", "Value": "baseball"}
```

```
"customer_interests": {"Type": "String.Array", "Value": "[\"baseball\"]"}
```

它也不符合以下訊息內文：

```
{
   "customer_interests": "baseball"
}
```

## 除外相符
<a name="string-anything-but-matching"></a>

當政策屬性值包含關鍵字 `anything-but`，就會比對*不*包含任何政策屬性值的任何訊息屬性或訊息內文值。`anything-but` 可以與 `"exists": false` 結合。對於`String.Array`類型屬性，如果政策屬性中未列出任何陣列元素，則會比對。

舉例下列政策屬性：

```
"customer_interests": [{"anything-but": ["rugby", "tennis"]}]
```

它符合下列任何訊息屬性：

```
"customer_interests": {"Type": "String", "Value": "baseball"}
```

```
"customer_interests": {"Type": "String", "Value": "football"}
```

```
"customer_interests": {"Type": "String.Array", "Value": "[\"rugby\", \"baseball\"]"}
```

它也符合以下任一訊息內文：

```
{
   "customer_interests": "baseball"
}
```

```
{
   "customer_interests": "football"
}
```

除此之外，它符合以下訊息屬性 (因為它包含的值*不是* `rugby` 或 `tennis`)：

```
"customer_interests": {"Type": "String.Array", "Value": "[\"rugby\", \"baseball\"]"}
```

它也符合以下訊息內文 (因為它包含的值不是 `rugby` 或 `tennis`)：

```
{
   "customer_interests": ["rugby", "baseball"]
}
```

不過，它不符合下列訊息屬性：

```
"customer_interests": {"Type": "String", "Value": "rugby"}
```

```
"customer_interests": {"Type": "String.Array", "Value": "[\"rugby\"]"}
```

它也不符合以下訊息內文：

```
{
   "customer_interests": ["rugby"]
}
```

**搭配 使用字首 `anything-but`**

針對字串比對，您也可以使用具 `anything-but` 運算子的字首。例如，下列政策屬性會拒絕 `order-` 字首：

```
"event":[{"anything-but": {"prefix": "order-"}}]
```

它符合以下任一屬性：

```
"event": {"Type": "String", "Value": "data-entry"}
```

```
"event": {"Type": "String", "Value": "order_number"}
```

它也符合以下任一訊息內文：

```
{
   "event": "data-entry"
}
```

```
{
   "event": "order_number"
}
```

但不符合以下訊息屬性：

```
"event": {"Type": "String", "Value": "order-cancelled"}
```

它也不符合以下訊息內文：

```
{
   "event": "order-cancelled"
}
```

**任何項目，但萬用字元**

下列政策屬性拒絕`*ball`萬用字元：

```
"customer_interests" : [{ "anything-but": { "wildcard": "*ball" }}]
```

它符合下列屬性：

```
{"customer_interests": ["hockey", "rugby", "soccer] }
```

不過，它不符合下列訊息屬性：

```
{"customer_interests": ["baseball", "basketball"] }
```

**anything-but 尾碼** 

下列政策屬性會拒絕 `-ball`

 尾碼：

```
"customer_interests": [ { "anything-but": { "suffix": "ball" } } ]
```

它符合下列屬性：

```
{"customer_interests": ["hockey", "rugby", "soccer] }
```

不過，它不符合下列訊息屬性：

```
 {"customer_interests": ["baseball", "basketball"] }
```

## 等於忽略大小寫相符
<a name="string-equals-ignore"></a>

當政策屬性包含關鍵字 `equals-ignore-case` 時，將對任何訊息屬性或內文屬性值執行不分大小寫的比對。

舉例下列政策屬性：

```
"customer_interests": [{"equals-ignore-case": "tennis"}]
```

它符合以下任一訊息屬性：

```
"customer_interests": {"Type": "String", "Value": "TENNIS"}
```

```
"customer_interests": {"Type": "String", "Value": "Tennis"}
```

它也符合以下任一訊息內文：

```
{
    "customer_interests": "TENNIS"
}
```

```
{
    "customer_interests": "teNnis"
{
```

## IP 地址比對
<a name="string-address-matching"></a>

您可以使用 `cidr` 運算子來檢查傳入訊息是否來自特定 IP 地址或子網路。

舉例下列政策屬性：

```
"source_ip":[{"cidr": "10.0.0.0/24"}]
```

它符合以下任一訊息屬性：

```
"source_ip": {"Type": "String", "Value": "10.0.0.0"}
```

```
"source_ip": {"Type": "String", "Value": "10.0.0.255"}
```

它也符合以下任一訊息內文：

```
{
   "source_ip": "10.0.0.0"
}
```

```
{
   "source_ip": "10.0.0.255"
}
```

但不符合以下訊息屬性：

```
"source_ip": {"Type": "String", "Value": "10.1.1.0"}
```

它也不符合以下訊息內文：

```
{
   "source_ip": "10.1.1.0"
}
```

## 前綴相符
<a name="string-prefix-matching"></a>

當政策屬性包含 `prefix` 關鍵字時，它符合任何以特定字元為開頭的訊息屬性或內文屬性值。

舉例下列政策屬性：

```
"customer_interests": [{"prefix": "bas"}]
```

它符合以下任一訊息屬性：

```
"customer_interests": {"Type": "String", "Value": "baseball"}
```

```
"customer_interests": {"Type": "String", "Value": "basketball"}
```

它也符合以下任一訊息內文：

```
{
   "customer_interests": "baseball"
}
```

```
{
   "customer_interests": "basketball"
}
```

但不符合以下訊息屬性：

```
"customer_interests": {"Type": "String", "Value": "rugby"}
```

它也不符合以下訊息內文：

```
{
   "customer_interests": "rugby"
}
```

## 後綴相符
<a name="string-suffix-matching"></a>

當政策屬性包含 `suffix` 關鍵字時，它符合任何以特定字元為結束的訊息屬性或內文屬性值。

舉例下列政策屬性：

```
"customer_interests": [{"suffix": "ball"}]
```

它符合以下任一訊息屬性：

```
"customer_interests": {"Type": "String", "Value": "baseball"}
```

```
"customer_interests": {"Type": "String", "Value": "basketball"}
```

它也符合以下任一訊息內文：

```
{
    "customer_interests": "baseball"
}
```

```
{
    "customer_interests": "basketball"
}
```

但不符合以下訊息屬性：

```
"customer_interests": {"Type": "String", "Value": "rugby"}
```

它也不符合以下訊息內文：

```
{
    "customer_interests": "rugby"
}
```

## 萬用字元
<a name="string-value-wildcard"></a>

 您可以使用萬用字元 (\*) 來比對事件模式中的字串值。

下列政策使用萬用字元 (\*) 字元：

```
"customer_interests": [ { "wildcard": "*ball" } ]
```

它符合下列屬性：

```
{"customer_interests": ["baseball", "basketball"] }
```