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 |
| A list of values that will be used to build the regular expression pattern. Can be used to retrieve context values from |
PARAM_2 | Optional string |
| 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 |
|
| Partial Match. Behaves like contains while being case-insensitive |
FullMatch |
|
| Adds the Fully matches the strings while being case-insensitive |
Exact |
|
| Adds the Fully matches the strings while being case-sensitive |
Context Filter Example:
For example, consider the following data source JSON:
{
"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:
$.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
$.result[?(@.group=~/(administrators|jira-core-users)/i)]
Same but with an array of groups in your data source
{
"result": [
{
"id": 1,
"groups": ["administrators","jira-servicedesk-users"],
"name": "Mario Speedwagon",
"username": "mario"
},
.... more items here ....
]
}
$.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
$.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
$.result[?(@.group=~{ REGEX_IN_ARRAY(( $.user.groups.items[*].name )) })]
$.result[?(@.group=~/(administrators|jira-core-users)/i)]
FullMatch
$.result[?(@.group=~{ REGEX_IN_ARRAY(( $.user.groups.items[*].name 'fullMatch')) })]
$.result[?(@.group=~/^(administrators|jira-core-users)$/i)]
Exact
$.result[?(@.group=~{ REGEX_IN_ARRAY(( $.user.groups.items[*].name 'exact')) })]
$.result[?(@.group=~/^(administrators|jira-core-users)$/)]
Anchor Effects
Anchor | Meaning |
---|---|
| Start of the string |
| End of the string |
| Partial/substring matching |
Construct Regex with JOIN function
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.