Count the number of instances a particular phrase appears in a text string

Hi,

I have a simple text string that appears like “Hello World , 4435 , Goodbye Moon , 5645 , Hello World , 54354”.

What I’d like is to set a variable with the count of the number of times the phrase ‘Hello World’ appears within the string. In the example above, this would output the value of ‘2’.

Any help appreciated! Thank you.

Welcome to the Make community!

Screenshot_2024-02-20_151445

You can use a Text Parser “Match Pattern” module with this Pattern (regular expression):

Hello World

Proof https://regex101.com/r/csuEAE

Important Info

  • :warning: Global match must be set to YES!

For more information, see Text Parser in the Make Help Center:

Match Pattern
The Match pattern module enables you to find and extract string elements matching a search pattern from a given text. The search pattern is a regular expression (aka regex or regexp), which is a sequence of characters in which each character is either a metacharacter, having a special meaning, or a regular character that has a literal meaning.

Then,

Every result (item/record) from a match module will output a bundle. To “combine” them into a single structure, you’ll need to use an aggregator of some sort.

Aggregators are modules that accumulate multiple bundles into one single bundle. An example of a commonly-used aggregator module is the Array aggregator module.

Finally,

You can use the built-in function length to count the number of items in the array.

e.g.:

{{ length(1.array) }}

For more information, see

2 Likes