Contact Us 1-800-596-4880

scan

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

Name Description

text

The input string to scan.

regex

A Java regular expression that describes the pattern match in the text.

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

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

Output

[ "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

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

Output

[
  [ "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.