Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

find

find(Array<T>, Any): Array<Number>

Returns the array of index where the element to be found where present

Transform

        
     
1
2
3
4
%dw 2.0
output application/json
---
["name", "lastName"] find "name"
Output

        
     
1
2
3
[
   0
]
find(String, Regex): Array<Array<Number>>

Returns the array of index where the regex matched in the text

Transform

        
     
1
2
3
4
%dw 2.0
output application/json
---
"DataWeave" find /a/
Output

        
     
1
2
3
[
   [1], [3], [6]
]
find(String, String): Array<Number>

Given a string, it returns the index position within the string at which a match was matched. If found in multiple parts of the string, it returns an array with the various idex positions at which it was found. You can either look for a simple string or a regular expression.

Transform

        
     
1
2
3
4
5
6
7
8
%dw 2.0
output application/json
---
{
  a: "aabccde" find /(a).(b)(c.)d/,
  b: "aabccdbce" find "a",
  c: "aabccdbce" find "bc"
}
Output

        
     
1
2
3
4
5
{
  "a": [[0,0,2,3]],
  "b": [0,1],
  "c": [2,6]
}