Nav

splitBy

splitBy(String, Regex): Array<String>

Splits a string into an array of separate elements. The function takes a regular expression to identify some portion of that string, and if it finds a match, uses the match as separator. splitBy performs the opposite operation of joinBy.

Using the regular expression \^$.|?*+()-, the following example finds the the hyphen (-) in the input string (a-b-c), so it uses the hyphen as a seperator.

Transform

        
     
1
2
3
4
%dw 2.0
output application/json
---
split: "a-b-c" splitBy(/\^$.|?*+()-/)
Output

        
     
1
2
3
{
  "split": ["a","b","c"]
}
splitBy(String, String): Array<String>

Splits a string into an array of separate elements. The function takes a another string to look for some portion of the input string, and if it finds a match, uses the match as separator. splitBy performs the opposite operation of joinBy.

The following example uses the hyphen (-) as the separator, but the separator could be any other character in the input, such as splitBy("b").

Transform

        
     
1
2
3
4
%dw 2.0
output application/json
---
split: "a-b-c" splitBy("-")
Output

        
     
1
2
3
{
  "split": ["a", "b", "c"]
}