Skip to main content
Skip table of contents

REGEX_IN_ARRAY

The REGEX_IN_ARRAY function is used to build a regular expression pattern from an array of values to perform a context filter operation. The resulting regex pattern is in the form /(VALUE1|VALUE2|...)/i.

Usable: Context Filter

Syntax: { REGEX_IN_ARRAY(( PARAM_1 PARAM_2)) }

Parameter

Type

Example

Description

PARAM_1

JSONPath Array

$.user.groups.items[*].name

A list of values that will be used to build the regular expression pattern. Can be used to retrieve context values from $.issue.... or $.user....

PARAM_2

Optional string

‘fullMatch'
'exact'

Optional value that supports two optional matching modes: fullMatch and exact, which affect how the resulting regular expression is constructed and applied.

Matching Modes

The PARAM_2 values in the REGEX_IN_ARRAY function changes how the values in the array are matched and what options are added to the regular expression.

Mode

Syntax Example

Anchors

Description

Default

{ REGEX_IN_ARRAY(( $.user.groups.items[*].name )) }

/(...)/i

Partial Match.

Behaves like contains while being case-insensitive

FullMatch

{ REGEX_IN_ARRAY(( $.user.groups.items[*].name 'fullMatch' )) }

/^(...)$/i

Adds the ^ and $ anchors.

Fully matches the strings while being case-insensitive

Exact

{ REGEX_IN_ARRAY(( $.user.groups.items[*].name 'exact' )) }

/^(...)$/

Adds the ^ and $ anchors and removes the i options.

Fully matches the strings while being case-sensitive

Context Filter Example:

For example, consider the following data source JSON:

CODE
{
  "result": [
    {
      "id": 1,
      "group": "administrators",
      "name": "Mario Speedwagon",
      "username": "mario"
    },
    .... more items here ....
  ]
}

To filter results based on whether the current user’s groups matches one of the values in the JSON array, use the following expression:

CODE
$.result[?(@.group=~{ REGEX_IN_ARRAY(( $.user.groups.items[*].name )) })]

If $.user.groups.items[*].name contains administrators and jira-core-users the expression will resolve to the regular expression

CODE
$.result[?(@.group=~/(administrators|jira-core-users)/i)]

Same but with an array of groups in your data source

CODE
{
  "result": [
    {
      "id": 1,
      "groups": ["administrators","jira-servicedesk-users"],
      "name": "Mario Speedwagon",
      "username": "mario"
    },
    .... more items here ....
  ]
}
CODE
$.result[?(@.group[?(@=~{ REGEX_IN_ARRAY(( $.user.groups.items[*].name )) })])]

If $.user.groups.items[*].name contains administrators and jira-core-users the expression will resolve to the regular expression

CODE
$.result[?(@.group[?(@=~/(administrators|jira-core-users)/i)])]

Mode Differences

Compare the resolved regular expression from the example above with all different modes and resolved anchors.

Default

CODE
$.result[?(@.group=~{ REGEX_IN_ARRAY(( $.user.groups.items[*].name )) })]
CODE
$.result[?(@.group=~/(administrators|jira-core-users)/i)]

FullMatch

CODE
$.result[?(@.group=~{ REGEX_IN_ARRAY(( $.user.groups.items[*].name 'fullMatch')) })]
CODE
$.result[?(@.group=~/^(administrators|jira-core-users)$/i)]

Exact

CODE
$.result[?(@.group=~{ REGEX_IN_ARRAY(( $.user.groups.items[*].name 'exact')) })]
CODE
$.result[?(@.group=~/^(administrators|jira-core-users)$/)]

Anchor Effects

Anchor

Meaning

^

Start of the string

$

End of the string

None

Partial/substring matching

Construct Regex with JOIN function

We use the method documented here to resolve the regex expression, but only support the options i, m, s, and x.

If the REGEX_IN_ARRAY function is constructing the expression in a way that is not feasible for your use case, you can use the JOIN function to construct an expression ‘manually’.

Instead of using $.result[?(@.group[?(@=~{ REGEX_IN_ARRAY(( $.user.groups.items[*].name )) })])] you can also use $.result[?(@.group[?(@=~/({ JOIN(( $.user.groups.items[*].name '|')) })/i)])]. This way, you are more flexible how to anchor or combine your expression.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.