Skip to main content

COUNTMATCH

Use the COUNTMATCH function to get the number of items in the array that match the regular expression pattern.

Use

COUNTMATCH( array, pattern )
Counts the number of items in the array that match the regular expression pattern.

ParameterRequiredDescription
arrayYesa Text, Choice, Date, Time or Date/Time array
patternYesa regular expression that determines which items will be counted

ReturnsNumber

Examples

Enforcing Mandatory Text Formats in an Array

In an Output Validation Formula, you can use COUNTMATCH to ensure that every entry in a multi-valued field (an array) adheres to a strict mandatory format, such as a code starting with specific letters followed by a set of numbers.

  • Scenario: A user provides a list of project IDs. Each ID must start with "abc" followed by exactly four numbers.
  • Formula: COUNTMATCH(this, "^abc\d{4}$") = COUNTALL(this)
  • Logic:
    • COUNTMATCH(this, "^abc\d{4}$"): This searches the current array (this) and counts how many items match the regular expression for "abc" followed by four digits.
    • COUNTALL(this): This counts the total number of items in the array, including any blank items.
    • Result: The validation only returns TRUE if every single item provided by the user matches the pattern. If even one entry is formatted incorrectly, the count from COUNTMATCH will be lower than the COUNTALL total, triggering a validation error.

Identifying and Counting Numeric Entries in a Text Array

You can use COUNTMATCH to identify specific types of data within a general text collection. This is useful for Conditional Branching or Variable Updates where the workflow needs to know the volume of specific content.

  • Scenario: An activity output called @Review.out.Notes contains several different text entries. You want to determine how many of these entries are purely numeric strings.
  • Formula: COUNTMATCH(@Review.out.Notes, "^\d+$")
  • Logic:
    • If the array @Review.out.Notes contains four items—for example: "hello", "12", "123", and "7"—the function will analyze each item against the digit pattern.
    • Result: The function will return 3, as "12", "123", and "7" match the pattern for numeric characters, while "hello" does not. This numerical result can then be used to route the approval or update a running total variable.