Splits a string into a string array based on a value of input or matches part of that input string. It filters out the matching part from the returned array. A string or a Java regular expression used to split the string. If it does not match some part of the string, the function will return the original, unsplit string in the array.
This version of splitBy
accepts a Java regular expression (regex) to match the input string. The regex can match any character in the input string. Note that splitBy
performs the opposite operation of joinBy
.
splitBy(text: String, regex: Regex): Array<String>
Name | Description |
---|---|
text | The input string to split. |
regex | A Java regular expression used to split the string. If it does not match some part of the string, the function will return the original, unsplit string in the array. |
This example uses a Java regular expression to split an address block by the periods and forward slash in it. Notice that the regular expression goes between forward slashes.
"Hello world"
%dw 2.0
output application/java
---
payload splitBy(/s/)
[Hello world]
%dw 2.0
output application/json
---
"192.88.99.0/24" splitBy(/[.\/]/)
["192", "88", "99", "0", "24"]
Splits a string into a string array based on a separating string that matches part of the input string. It also filters out the matching string from the returned array.
The separator can match any character in the input. Note that splitBy
performs the opposite operation of joinBy
.
splitBy(text: String, separator: String): Array<String>
Name | Description |
---|---|
text | The string to split. |
separator | A string used to separate the input string. If it does not match some part of the string, the function will return the original, unsplit string in the array. |
This example splits a string containing an IP address by its periods.
%dw 2.0
output application/json
---
"192.88.99.0" splitBy(".")
["192", "88", "99", "0"]
Helper function that enables splitBy
to work with a null
value.
If you like my post please follow me to read my latest post on programming and technology.
You are given a stream of elements that is too large to fit into memory.…
The formula for the area of a circle is given by πr². Use the Monte…
Given an integer k and a string s, write a function to determine the length…
There is a staircase with N steps, and you can ascend either 1 step or…
Build an autocomplete system that, given a query string s and a set of possible…
Design a job scheduler that accepts a function f and an integer n. The scheduler…