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

ExtractRegExGroup - script and chart function

ExtractRegExGroup() extracts text from an input string expression using the composite regular expression pattern that is specified. When using the function, specify the group to use within the composite regex. The function returns a null value if no matches are found.

If you use the ExtractRegExGroup() function in a LOAD statement and field_no is omitted, then the function will return multiple records. If several fields are loaded using ExtractRegExGroup(), the Cartesian products of all combinations are created.

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

Syntax:  

ExtractRegExGroup (text, regex, group [, field_no])

Return data type: string

Arguments
Argument Description
text String expression containing the text to be extracted in the return value.
regex The regular expression to use for extracting text.
group

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

If the regular expression only contains one group, use the ExtractRegEx() function instead. Alternatively, use ExtractRegExGroup() with a group value of 0.

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

field_no

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

This is an optional argument. Default is 1 if not specified.

Function examples
Example Result
ExtractRegExGroup('abc123 def456','([a-z]+)([0-9]+)',1) Returns abc (first group of first match).
ExtractRegExGroup('abc123 def456','([a-z]+)([0-9]+)',1,2) Returns def (first group of second match).
ExtractRegExGroup('abc123 def456','([a-z]+)([0-9]+)',2) Returns 123 (second group of first match).
ExtractRegExGroup('abc123 def456','([a-z]+)([0-9]+)',2,2) Returns 456 (second group of second match).

When to use it

You can use Extract RegEx() to extract information that you want to isolate from data that might also contain other information (for example, free text or JSON strings). For example:

  • Extract email addresses, telephone numbers, account numbers, and other information from text.

  • Extract numeric values from text (for example, currency).

  • Standardize formatting of text or numeric data.

Example 1 – load script to parse transaction codes

Example 2 – load script to extract business contact information

Example 3 – load script to extract components from ISBN codes

Example 4 – chart expressions to extract business contact information (with ExtractRegEx() comparison)

Example 5 – URL parsing (with ExtractRegEx() 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!