---
schema_version: "1"
id: a1022186a7188e6860a635747faede967d6e42f0110baaf45d00f2ccd6af3be4
title: contains
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.7/dw-core-functions-contains.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.7/dw-core-functions-contains
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 2381ec3059f4a4af8028920f3a0ba8833b773ed5d95ee7a888709cd47f66c17d
description: MuleSoft Documentation Site
release: "2.7"
latest: false
---
# contains

## [](#contains1)contains<T>(@StreamCapable items: Array<T>, element: Any): Boolean

入力に特定の値が含まれる場合は ​`true`​、それ以外の場合は ​`false`​ を返します。

このバージョンの ​`contains`​ は、入力として配列を受け入れます。その他のバージョンは文字列を受け入れ、別の文字列または正規表現を使用して一致があるかどうかを判別できます。

### [](#パラメーター)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>items</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">入力配列。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>elements</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">配列内で検索する要素。サポートされている任意のデータ型にできます。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、入力配列内の ​`2`​ を検索し、​`true`​ を返します。

#### [](#ソース)ソース

```DataWeave
%dw 2.0
output application/json
---
[ 1, 2, 3, 4 ] contains(2)
```

#### [](#出力)出力

```JSON
true
```

### [](#例-2)例

次の例では、入力配列に「3」が含まれるかどうかを示します。

#### [](#ソース-2)ソース

```DataWeave
%dw 2.0
output application/json
---
ContainsRequestedItem: payload.root.*order.*items contains "3"
```

#### [](#入力)入力

```XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <order>
      <items>155</items>
    </order>
    <order>
      <items>30</items>
    </order>
    <order>
      <items>15</items>
    </order>
    <order>
      <items>5</items>
    </order>
    <order>
      <items>4</items>
      <items>7</items>
    </order>
    <order>
      <items>1</items>
      <items>3</items>
    </order>
    <order>
        null
    </order>
</root>
```

#### [](#出力-2)出力

```JSON
{ "ContainsRequestedItem": true }
```

## [](#contains2)contains(text: String, toSearch: String): Boolean

文字列に特定のサブ文字列が含まれるかどうかを示します。​`true`​ または ​`false`​ を返します。

### [](#パラメーター-2)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>text</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">入力文字列 (​<code>String</code>​ (文字列))。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>toSearch</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">入力文字列内で検索するサブ文字列 (​<code>String</code>​ (文字列))。</p></td>
</tr>
</tbody>
</table>

### [](#例-3)例

次の例では、入力文字列「mulesoft」内の「mule」を検索し、​`true`​ を返します。

#### [](#ソース-3)ソース

```DataWeave
%dw 2.0
output application/json
---
"mulesoft" contains("mule")
```

#### [](#出力-3)出力

```JSON
true
```

### [](#例-4)例

次の例では、​`"some string"`​ 内のサブ文字列 ​`"me"`​ を検索し、​`true`​ を返します。

#### [](#ソース-4)ソース

```DataWeave
%dw 2.0
output application/json
---
{ ContainsString : payload.root.mystring contains("me") }
```

#### [](#入力-2)入力

```XML
<?xml version="1.0" encoding="UTF-8"?>
<root><mystring>some string</mystring></root>
```

#### [](#出力-4)出力

```JSON
{ "ContainsString": true }
```

## [](#contains3)contains(text: String, matcher: Regex): Boolean

文字列に正規表現との一致が含まれる場合は ​`true`​、 それ以外の場合は ​`false`​ を返します。

### [](#パラメーター-3)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>text</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">入力文字列。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>matcher</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">入力 ​<code>text</code>​ (テキスト) 内の文字を照合する Java 正規表現。</p></td>
</tr>
</tbody>
</table>

### [](#例-5)例

次の例では、入力の ​`mulesoft`​ 内に ​`e`​ から ​`g`​ までの任意の文字があるかどうかを確認し、​`true`​ を返します。

#### [](#ソース-5)ソース

```DataWeave
%dw 2.0
output application/json
---
contains("mulesoft", /[e-g]/)
```

#### [](#出力-5)出力

```JSON
true
```

### [](#例-6)例

次の例では、​`"A very long string"`​ 内の ​`/s[t|p]rin/`​ との一致を検索し、 ​`true`​ を返します。正規表現内の ​`[t|p]`​ は ​`t`​ または ​`p`​ を意味します。

#### [](#ソース-6)ソース

```DataWeave
%dw 2.0
output application/json
---
ContainsString: payload.root.mystring contains /s[t|p]rin/
```

#### [](#入力-3)入力

```XML
<?xml version="1.0" encoding="UTF-8"?>
<root><mystring>A very long string</mystring></root>
```

#### [](#出力-6)出力

```JSON
{ "ContainsString": true }
```

## [](#contains4)contains(text: Null, matcher: Any): false

`contains`​ を ​`null`​ 値に使用できるようにするヘルパー関数。

_DataWeave バージョン 2.4.0 で導入されました。_