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.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…