Nav

match

match(String, Regex): Array<String>

Matches a string against a regular expression and returns an array that contains the entire matching expression, followed by all of the capture groups that match the provided regex.

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

Transform

        
     
1
2
3
4
%dw 2.0
output application/json
---
hello: "anniepoint@mulesoft.com" match(/([a-z]*)@([a-z]*).com/)
Output

        
     
1
2
3
4
5
6
7
{
  "hello": [
    "anniepoint@mulesoft.com",
    "anniepoint",
    "mulesoft"
  ]
}

In the example above, the regular expression describes an email address. It contains two capture groups, what is before and what is 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.