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

# scan

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

## scan(text: String, matcher: Regex): Array<Array<String>>

Returns an array with all of the matches found in an input string.

Each match is returned as an array that contains the complete match followed by any capture groups
in your regular expression (if present).

### 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>The input string to scan.</p></td></tr><tr><td><p><code>regex</code></p></td><td><p>A Java regular expression that describes the pattern match in the <code>text</code>.</p></td></tr></tbody></table>

### Example

In this example, the `regex` describes a URL. It contains three capture groups within the
parentheses, the characters before and after the period (`.`). It produces an array of matches to
the input URL and the capture groups. It uses `flatten` to change the output from an array of arrays
into a simple array. Note that a `regex` is specified within forward slashes (`//`).

#### Source

```DataWeave
%dw 2.0
output application/json
---
flatten("www.mulesoft.com" scan(/([w]*)\.([a-z]*)\.([a-z]*)/))
```

#### Output

```JSON
[ "www.mulesoft.com", "www", "mulesoft", "com" ]
```

### Example

In the example, the `regex` describes an email address. It contains two capture groups, the
characters before and after the `@`. It produces an array matches to the email addresses and capture
groups in the input string.

#### Source

```DataWeave
%dw 2.0
output application/json
---
"anypt@mulesoft.com,max@mulesoft.com" scan(/([a-z]*)@([a-z]*).com/)
```

#### Output

```JSON
[
  [ "anypt@mulesoft.com", "anypt", "mulesoft" ],
  [ "max@mulesoft.com", "max", "mulesoft" ]
]
```

## scan(text: Null, matcher: Any): Null

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

_Introduced in DataWeave version 2.4.0._
