Contact Free trial Login

match

match(String, Regex): Array<String>

Uses an regular expression to match string and then separate it into capture groups. Returns the results in a a list (an array).

It can be applied to the result of any evaluated expression and can return any evaluated expression. See Pattern Matching in DataWeave.

Parameters

Name Description

text

A string (String type).

matcher

A regular expression for matching characters in the text.

Example

In this example, the regular expression describes an email address. It contains two capture groups: what come before and after the @. The result is an array of three elements: the first is the whole email address, the second matches one of the capture groups, the third matches the other one.

Source

%dw 2.0
output application/json
---
{ "hello" : "anniepoint@mulesoft.com" match(/([a-z]*)@([a-z]*).com/) }

Output

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

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.