---
schema_version: "1"
id: 0f8215e43ef7ed3cac73e62efe486c0c823b54155ee14ac4f4983d69e03d1a42
title: countMatches
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.6/dw-strings-functions-countmatches.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.6/dw-strings-functions-countmatches
source_site: docs.mulesoft.com
content_type: documentation
content_hash: b90f3b57720c9e81b757385071276610250961c05955554b1484267625e282e2
description: MuleSoft Documentation Site
release: "2.6"
latest: false
---
# countMatches

## [](#countmatches1)countMatches(text: String, pattern: String): Number

文字列内の一致の数を数えます。

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

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

<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>pattern</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">テキスト内で検索するサブ文字列。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、文字列内の一致を数えています。

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

```DataWeave
%dw 2.0
import countMatches from dw::core::Strings
output application/json
---
"hello worlo!" countMatches "lo"
```

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

```Json
2
```

## [](#countmatches2)countMatches(text: String, pattern: Regex): Number

正規表現が文字列内のテキストに一致する回数を数えます。

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

### [](#パラメーター-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">一致を検索する文字列。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pattern</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">検索で使用する正規表現パターン。</p></td>
</tr>
</tbody>
</table>

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

次の例では、文字列内の母音を数えています。

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

```DataWeave
%dw 2.0
import countMatches from dw::core::Strings
output application/json
---
"hello, ciao!" countMatches /[aeiou]/
```

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

```Json
5
```

## [](#countmatches3)countMatches(text: Null, pattern: Any): Null

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

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