REGEX_REPLACE
The REGEX_REPLACE function is used to match a regular expression pattern against a string content and replace all matches with a given string
Usable: Value Fields, Context Filter
Syntax: { REGEX_REPLACE((PARAM_1 PARAM_2 PARAM_3)) }
Parameter | Type | Example | Description |
---|---|---|---|
PARAM_1 | JSONPath value |
| The JSONPath expression representing the value that should be matched against the regular expression pattern. |
PARAM_2 | String |
| The regular expression pattern to match against the value in PARAM_1 |
PARAM_3 | String |
| The replacing String of each match |
Value Field Example
Extract all text up to the first whitespace:
{ REGEX_REPLACE(($.value '[^a-zA-Z0-1 ]' '')) }
If $.value
contains '[remove] all // unwanted {}'&^!@^&($ characters'
the result will be remove all unwanted characters
.
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 in which the id
equals the custom field value of the issue until the first whitespace:
$.result[?(@.id=={ REGEX_REPLACE(($.issue.fields.customfield_X '[^0-1 ]' '')) } )]
If the $.issue.fields.customfield__X
field contains '1 (branch/name)'
the resolved expression will be:
$.result[?(@.id==1)]
because only numbers are allowed and other characters are removed