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

IndexRegExGroup - script and chart function

IndexRegExGroup() searches the input string and returns the starting position of the nth occurrence of the composite regular expression pattern that is specified. An optional fourth argument count provides the value of n, which is 1 if omitted. The positions in the string are numbered left to right from 1 and up. If no match is found, the function returns 0.

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

Syntax:  

IndexRegExGroup (text, regex, group [, count])

Return data type: integer

Arguments
Argument Description
text The input string text within which you want to search for a regular expression.
regex The regular expression to use for searching the input string.
group

The number of the group, in the case of a composite regular expression.

A group value of 0 returns the index of the entire regex. However, if the regular expression only needs to return the index of the entire match, use the IndexRegEx() function instead.

You can specify a negative group value to search for matches from right to left.

count

The number of the match. This is useful when multiple matches for the regular expression might be found in the text. For example, specify a value of 4 to search for the position of the fourth match.

This is an optional argument. Default is 1 if not specified. You can specify a negative value to search for matches from right to left.

Function examples
Example Result
IndexRegExGroup('abc123','([a-z])([0-9]+)',0) Returns 3 (start position of complete regex).
IndexRegExGroup('abc123','([a-z])([0-9]+)',1) Returns 3 (start position of first group).
IndexRegExGroup('abc123','([a-z])([0-9]+)',2) Returns 4 , which is the start position of the second group. In the input regex pattern, the string ([0-9]+) corresponds to the second group.
IndexRegExGroup('ABC123','([a-z])([0-9]+)',1) Returns 0, because IndexRegExGroup() is case-sensitive.
IndexRegExGroupI('ABC123','([a-z])([0-9]+)',1) Returns 3. The case-insensitive variant of the function, IndexRegExI(), is used.

When to use it

Use cases for this function include:

  • Identifying where specific text patterns occur within larger bodies of text. For example, you might want to know where the domain of an email address is used across a series of long email messages.

  • IndexRegExGroup() is particularly useful for advanced data processing, and is commonly used in the first step of a longer, more complex transformation. It is typically easier to solve problems with other regex functions such as ExtractRegExGroup(), MatchRegEx(), and CountRegEx(), but there may be times when IndexRegExGroup() offers solutions that these functions cannot provide.

Example 1 – load script to find positions of ISBN components

Example 2 – chart expressions to find URL positions (with IndexRegEx() comparison)

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!