substringBy(text: String, predicate: (character: String, index: Number) -> Boolean): Array<String>

Splits a string at each character where the predicate expression returns true.

Introduced in DataWeave version 2.4.0.


Name Description


The string to split. The string is treated as an array of characters.


Expression that tests each character and returns a Boolean value. The expression can iterate over each character and index of the string.


This example splits a string where any of the specified characters ("~", "=", or "_") are present.


%dw 2.0
import substringBy from dw::core::Strings
output application/json
"hello~world=here_data-weave" substringBy $ == "~" or $ == "=" or $ == "_"


["hello", "world", "here", "data-weave"]

substringBy(text: Null, predicate: (character: Nothing, index: Nothing) -> Any): Null

Helper function that enables substringBy to work with a null value.

Introduced in DataWeave version 2.4.0.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub
Submit your feedback!
Share your thoughts to help us build the best documentation experience for you!
Take our latest survey!