---
schema_version: "1"
id: 7c744de9d6d5b42577996e4c73d1281bcf9cfabd2a5dfc40dcd3cad9d5f0cb23
title: contains
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dw-core-functions-contains.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dw-core-functions-contains
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 3ce45c3cefe4aad1f4cc0ae350c1b90a3f312d7f33bb1d127ce812b1f75080f7
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
---

# contains

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

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

Returns `true` if an input contains a given value, `false` if not.

This version of `contains` accepts an array as input. Other versions accept a string and can use
another string or regular expression to determine whether there is a match.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>items</code></p></td><td><p>The input array.</p></td></tr><tr><td><p><code>elements</code></p></td><td><p>Element to find in the array. Can be any supported data type.</p></td></tr></tbody></table>

### Example

This example finds that `2` is in the input array, so it returns `true`.

#### Source

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

#### Output

```JSON
true
```

### Example

This example indicates whether the input array contains '"3"'.

#### Source

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

#### Input

```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>
```

#### Output

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

## contains(text: String, toSearch: String): Boolean

Indicates whether a string contains a given substring. Returns `true` or `false`.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>text</code></p></td><td><p>An input string (a <code>String</code>).</p></td></tr><tr><td><p><code>toSearch</code></p></td><td><p>The substring (a <code>String</code>) to find in the input string.</p></td></tr></tbody></table>

### Example

This example finds "mule" in the input string "mulesoft", so it returns `true`.

#### Source

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

#### Output

```JSON
true
```

### Example

This example finds that the substring `"me"` is in `"some string"`, so it returns `true`.

#### Source

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

#### Input

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

#### Output

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

## contains(text: String, matcher: Regex): Boolean

Returns `true` if a string contains a match to a regular expression, `false` if not.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>text</code></p></td><td><p>An input string.</p></td></tr><tr><td><p><code>matcher</code></p></td><td><p>A Java regular expression for matching characters in the input <code>text</code>.</p></td></tr></tbody></table>

### Example

This example checks for any of the letters `e` through `g` in the input `mulesoft`, so it returns
`true`.

#### Source

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

#### Output

```JSON
true
```

### Example

This example finds a match to `/s[t|p]rin/` within `"A very long string"`, so it returns `true`. The
`[t|p]` in the regex means `t` or `p`.

#### Source

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

#### Input

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

#### Output

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

## contains(text: Null, matcher: Any): false

Helper function that enables `contains` to work with a `null` value.

_Introduced in DataWeave version 2.4.0._
