The occurrences helper returns the number of times a specified substring appears in a string. Use it to count keyword matches, delimiters, or repeated patterns in text fields.
Syntax
{{occurrences str substring}}
str -- The input string to search. Required.
substring -- The substring to count. Required. Matching is case-sensitive: "Foo" and "foo" are counted separately.
Examples
Count word occurrences
{{occurrences record.text "foo"}}
Input:
{ "record": { "text": "foo bar foo bar baz" } }
Output: 2
Count delimiter occurrences
{{occurrences record.path "/"}}
Input:
{ "record": { "path": "/api/v1/resource/item" } }
Output: 4
Count character occurrences
{{occurrences record.name "a"}}
Input:
{ "record": { "name": "Banana" } }
Output: 3
"Banana" contains three lowercase "a" characters. The uppercase "B" is not counted.
Usage notes
- Matching is case-sensitive:
"Foo"and"foo"are treated as different substrings. - Overlapping matches are not counted separately.
- Returns
0if the substring is not found.