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

ExtractRegEx - script and chart function

ExtractRegEx() extracts text from an input string expression using the specified regular expression pattern. The function returns a null value if no matches are found.

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

Syntax:  

ExtractRegEx (text, regex [, 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.
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. Specify a negative value to reverse the order of the matches.

The following apply regardless of whether the function is used in a load script or chart expression:

  • If field_no is positive, the function will return one value, identifying matches from left to right.

  • If field_no is negative, the function will return one value, identifying matches from right to left.

When using the function in a load script:

  • If you use the ExtractRegEx() function in a LOAD statement and field_no is omitted, the function generates as many records as there are matches.

  • If several fields are loaded using ExtractRegEx() and none of them specify a field_no argument, the Cartesian products of all combinations are created.

When using the function in a chart expression:

  • If the field_no is omitted, the default value is 1.

Function examples
Example Result
ExtractRegEx('a,b c;1 2,3','[a-z]|[0-9]', 1) Returns a, which is the first match found.
ExtractRegEx('a,b c;1 2,3','[a-z]|[0-9]', 2) Returns b, which is the second match found.
ExtractRegEx('a,b c;1 2,3','[a-z]|[0-9]', 4) Returns 1, which is the fourth match found.
ExtractRegEx('abc','a|b',-1) Returns b. When a negative value is specified, matches are counted in reverse.
ExtractRegEx('A,B C;1 2,3','[a-c]|[4-9]') Returns a null value, because ExtractRegEx() is case-sensitive, and the case-insensitive variant was not used.
ExtractRegExI('A,B C;1 2,3','[a-c]|[4-9]') Returns A, because the case-insensitive variant ExtractRegExI() was used.

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 extract email addresses from JSON

Example 2 – load script to extract numeric values from currency amounts

Example 3 – chart expressions to extract email addresses from JSON

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!