%dw 2.0
output application/json
---
"192.88.99.0/24" splitBy(/[.\/]/)
splitBy
DataWeave 2.2 is compatible and bundled with Mule 4.2. This version of Mule reached its End of Life on May 2, 2023, when Extended Support ended. Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted. MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements. |
splitBy(String, Regex): Array<String>
Splits a string into a string array based on a value that matches part of that string. It filters out the matching part from the returned 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
.
Parameters
Name | Description |
---|---|
|
The input string to split. |
|
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. |
Example
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.
Example
This example uses several regular expressions to split input strings. The
first uses \/^*.b./\
to split the string by -b-
. The second uses /\s/
to split by a space. The third example returns the original input string in
an array ([ "no match"]
) because the regex /^s/
(for matching the first
character if it is s
) does not match the first character in the input
string ("no match"
). The fourth, which uses /^n../
, matches the first
characters in "no match"
, so it returns [ "", "match"]
. The last removes
all numbers and capital letters from a string, leaving each of the lower case
letters in the array. Notice that the separator is omitted from the output.
splitBy(String, String): Array<String>
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
.
Parameters
Name | Description |
---|---|
|
The string to split. |
|
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. |
Example
The first example (splitter1
) uses a hyphen (-
) in "a-b-c"
to split the
string. The second uses an empty string (""
) to split each character
(including the blank space) in the string. The third example splits based
on a comma (,
) in the input string. The last example does not split the
input because the function is case sensitive, so the upper case NO
does not
match the lower case no
in the input string. Notice that the separator is
omitted from the output.