%dw 2.0
import countMatches from dw::core::Strings
output application/json
---
"hello worlo!" countMatches "lo"
DataWeave
countMatches
countMatches(text: String, pattern: String): Number
Counts the number of matches in a string.
Introduced in DataWeave version 2.4.0.
Parameters
Name | Description |
---|---|
|
The string to search for matches. |
|
A substring to find in the text. |
Example
This example counts matches in a string.
Source
Output
2
Json
countMatches(text: String, pattern: Regex): Number
Counts the number of times a regular expression matches text in a string.
Introduced in DataWeave version 2.4.0.
Parameters
Name | Description |
---|---|
|
The string to search for matches. |
|
The regex pattern to use in the search. |
Example
This example counts the vowels in a string.
Source
%dw 2.0
import countMatches from dw::core::Strings
output application/json
---
"hello, ciao!" countMatches /[aeiou]/
DataWeave
Output
5
Json
countMatches(text: Null, pattern: Any): Null
Helper function that enables countMatches
to work with a null
value.
Introduced in DataWeave version 2.4.0.