scan

DataWeave 2.1 is compatible with Mule 4.1. Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule will reach its End of Life on November 2, 2022, when Extended Support ends.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

scan(String, Regex): Array<Array<String>>

Returns a list (array) with all of the matches found within the given 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 text to scan (String type).

regex

A regular expression that describes the pattern to look for in the text.

Example

In the example, the regex describes an email address. It contains two capture groups, the characters before and after the @. It produces an an array matching the two email addresses in the input string. Each match is an array of three elements: The first is the entire email address, and the second and third are matches to the regex capture groups.

Source

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

Output

{
  "hello": [
    [
      "anypt@mulesoft.com",
      "anypt",
      "mulesoft"
    ],
    [
      "max@mulesoft.com",
      "max",
      "mulesoft"
    ]
  ]
}

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub