# IsRegEx - script and chart function

IsRegEx() returns whether the specified text is a valid regular expression.

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

Syntax:

IsRegEx (expr [, debug])

Return data type: dual

Arguments

| Argument | Description |
| --- | --- |
| expr | String expression containing the regular expression to evaluate. |
| debug | Optional argument. If any value is specified for this argument, the expression returns a text hint outlining how an invalid regular expression might be fixed. |

Function examples

| Example | Result |
| --- | --- |
| `IsRegEx('[a-z]')` | Returns `-1` (true). |
| `IsRegEx(']0-1[', 1)` | This example returns an error message with a hint to correct the invalid regular expression `]0-1[`. |
| `IsRegEx('[a-z')` | Returns `0` (false). No error message is shown because the debug argument is not specified. |

## When to use it

You can use IsRegEx() to test whether the regular expressions you write are valid in Qlik Sense. For example, you can load a table into your app with input text and an evaluation of the text's validity as regex.

## Example 1 – loading validity of regex into data model

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/IsRegEx.htm)

#### Load script and results

Overview

Open the Data load editor and add the load script below to a new section.

The load script contains:

* A field, `reg_exp`, containing input strings that may or may not be valid regular expressions.

* Two calculated fields to check if each value in `reg_exp` is a valid regular expression or not:

  * `validity_no_hint`: Displays `-1` (true) if the regex is valid, and 0 (false) if it is invalid.

  * `validity_with_hint`: Displays -1 (true) if the regex is valid. If the regex is invalid, an autogenerated error message outlines issues with the input, with possible hints to help fix it.

Load script

```
[Expression Validity]:
	Load
		*,
		IsRegEx(reg_exp) as validity_no_hint,
		IsRegEx(reg_exp,1) as validity_with_hint
		;
Load
*
Inline
`
reg_exp
[a-z]+
([a-z)(0-9)+
abcdefg|[0-7
\$|¢(0-9)
`;
```

Results

Load the data and open a sheet. Create a new table and add these fields as dimensions:

* `
  reg_exp`

* `validity_no_hint`

* `validity_with_hint`

Results table

| reg\_exp | validity\_no\_hint | validity\_with\_hint |
| --- | --- | --- |
| ([a-z)(0-9)+ | 0 | -1 |
| [a-z]+ | -1 | Hint text (autogenerated) |
| \$\|¢(0-9) | -1 | Hint text (autogenerated) |
| abcdefg\|[0-7 | 0 | -1 |

## Example 2 – only loading valid regex into data model

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/IsRegEx.htm)

#### Load script and results

Overview

Open the Data load editor and add the load script below to a new section.

The load script contains:

* A field, `reg_exp`, containing input strings that may or may not be valid regular expressions. This field is contained in a table named `Regular Expressions`.

* A where clause that only loads records into the data model when the input is a valid regular expression.

Load script

```
[Regular Expressions]:

Load
*
Inline
`
reg_exp
[a-z]+
([a-z)(0-9)+
abcdefg|[0-7
\$|¢(0-9)
`
WHERE
IsRegEx(reg_exp)=True()
;
```

Results

Load the data and open a sheet. Create a new table and add this field as a dimension:

* `
  reg_exp`

Results table

| reg\_exp |
| --- |
| [a-z]+ |
| \$\|¢(0-9) |

`[a-z]+` and `\$|¢(0-9)` are valid regular expressions, so they have been loaded into the data model. `([a-z)(0-9)+` and `abcdefg|[0-7` are not valid regular expressions, so they are not loaded into the data model.

## Example 3 – chart expressions

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/IsRegEx.htm)

#### Chart expressions and results

Overview

In this example, we load a set of input strings into the data model and add them to a table, along with two calculated dimensions which evaluate the validity of the regex. The two calculated dimensions convey the same information in different ways.

Open the Data load editor and add the following load script to a new section.

The load script contains a field, `reg_exp`, containing input strings that may or may not be valid regular expressions. This field is contained in a table named `Regular Expressions`.

Load script

```
[Regular Expressions]:

Load
*
Inline
`
reg_exp
[a-z]+
([a-z)(0-9)+
abcdefg|[0-7
\$|¢(0-9)
`;
```

Results

Do the following:

1. Load the data and open a sheet. Create a new table. Add `reg_exp` as a dimension .

2. Next, add the following calculated dimension:

   `=IsRegEx(reg_exp)`

   This is a basic chart expression that shows `-1` (true) if the input is a valid regular expression, and `0` (false) if it is not.

3. Add another calculated dimension:

   `=if(IsRegEx(reg_exp), 'Valid regex', 'Invalid regex')`

   This is a conditional expression that offers more detail into the validity of the input.

Results table

| reg\_exp | =IsRegEx(reg\_exp) | =if(IsRegEx(reg\_exp), 'Valid regex', 'Invalid regex') |
| --- | --- | --- |
| ([a-z)(0-9)+ | 0 | Invalid regex |
| [a-z]+ | -1 | Valid regex |
| \$\|¢(0-9) | -1 | Valid regex |
| abcdefg\|[0-7 | 0 | Invalid regex |

## Learn more

* [Working with regular expressions in load scripts and chart expressions](https://help.qlik.com/en-US/sense/May2025/Subsystems/Hub/Content/Sense_Hub/Scripting/regular-expressions-qlik-analytics.htm)