Early Access: The content on this website is provided for informational purposes only in connection with pre-General Availability Qlik Products.
All content is subject to change and is provided without warranty.
Skip to main content Skip to complementary content

CountRegEx - script and chart function

CountRegEx() returns the number of occurrences of the specified regular expression pattern in the input string text. If there is no match, 0 is returned.

This function performs regex operations that are case-sensitive. You can alternatively use the variant CountRegExI() to perform case-insensitive regex operations.

Syntax:  

CountRegEx (text, regex)

Return data type: numeric

Arguments
Argument Description
text The input string text within which you want to search for a regular expression.
regex The regular expression pattern to search for.
Function examples
Example Result
CountRegEx('abc123','[a-z]') Returns 3.
CountRegEx('abc123','[a-z][0-9]') Returns 1.
CountRegEx('abc123','[0-9]') Returns 3.
CountRegEx('ABC','[a-z]{3}') Returns 0.
CountRegExI('ABC','[a-z]{3}') Returns 1. Because the CountRegExI() variant is used, text searches are not case-sensitive.

When to use it

Examples of use cases for CountRegEx() include:

  • Counting the number of times a particular text pattern occurs within a string. For example, you could search for instances of email addresses, telephone numbers, and other information within documents and email messages.

  • Validating whether data matches a specific syntax requirement. For example, you could identify occurrences of error in data entry.

Example 1 – load script to count valid year ranges

Example 2 – load script to count number of email addresses in text strings

Example 3 – chart expression to count occurrences of string

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!