> ## Documentation Index
> Fetch the complete documentation index at: https://learn.workflow.dog/llms.txt
> Use this file to discover all available pages before exploring further.

# Count Occurrences

> Count literal text or regular-expression matches inside a string.

The **Count Occurrences** action counts how many times a literal string or
regular-expression separator appears in text. Switch **Use Regex** to choose
the matching mode.

## Inputs

| Input              | Type               | Required  | Description                                                   |
| ------------------ | ------------------ | --------- | ------------------------------------------------------------- |
| **Text**           | String             | Yes       | The text to search.                                           |
| **Use Regex**      | Boolean            | Yes       | Shows either the literal-text or regex inputs.                |
| **Search Text**    | String             | Sometimes | The literal text to count when **Use Regex** is off.          |
| **Ignore Case**    | Boolean            | No        | Makes literal matching case-insensitive. Defaults to `false`. |
| **Search Pattern** | Regular expression | Sometimes | The pattern used when **Use Regex** is on.                    |

## Outputs

| Output    | Type   | Description                      |
| --------- | ------ | -------------------------------- |
| **Count** | Number | The number of occurrences found. |

## Choose a matching mode

<Tabs>
  <Tab title="Literal text">
    Literal mode searches for the exact characters in **Search Text**. Turn on
    **Ignore Case** to compare lowercase versions of the text and search value.

    With **Text** set to `Error: error: ERROR` and **Search Text** set to
    `error`, the count is `1` by default or `3` when case is ignored.
  </Tab>

  <Tab title="Regular expression">
    Regex mode accepts a value from **Regular Expression**. Use a pattern when
    the matching text varies, such as `INV-\d+`.

    Regex flags are preserved. A case-insensitive pattern can count different
    letter cases without using the literal-mode **Ignore Case** option.
  </Tab>
</Tabs>

<Warning>
  Avoid capture groups in the regex used for this action. The implementation
  counts the pieces produced by splitting the text, and captured values are
  included in that result. Use non-capturing groups such as `(?:foo|bar)` when
  grouping is required.
</Warning>

The action counts non-overlapping occurrences. For example, searching for `aa`
in `aaa` returns `1`.
