Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue Linking Using Regex in Jira Automation

Milena Prieto October 19, 2023

Hello Jira Community,

I'm facing an issue with using regular expressions (regex) in Jira Automation to link one issue to another based on a custom field. I'm having trouble getting the regex to work correctly in Jira Automation, even though it functions as expected on online regex testers like regex101.com and freeformatter.com.

Here's an example of what I'm trying to achieve: I want to extract the last string after a slash (/) or an equal sign (=) from a URL (stored as text in a custom field). In other words, in the following inputs, the expected result of the regex should be "US-61" and "US-70," respectively:

I've been attempting to use the following regex pattern:

[^=\/]+(\/)?$

I've placed this regex within a smart value, so it looks like this:

{{fields.customfield_10184.match("[^=\/]+(\/)?$")}}

However, it doesn't return any results in Jira Automation.

When I tested with two different regex patterns (one to capture the last value after an equal sign and another to capture the last value after a slash), it worked as expected.

Please keep in mind that I tested all these regex patterns in online validators, and they worked as intended.

Can someone help me understand why this regex pattern isn't working in Jira Automation and suggest a solution?

Thank you for your assistance!

 

UPDATE: 

I tried to use the following regex:

  • ([A-Z]{2,}-\d+).*
  • [A-Z]{2,}-\d+.*

But it's not recognized as a smart value, unlike the previous one.

image.png

 

Here's the smart value:

{{fields.customfield_10184.match("([A-Z]{2,}-\d+).*")}}

1 answer

1 accepted

2 votes
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 19, 2023

Hi @Milena Prieto -- Welcome to the Atlassian Community!

First thing, context is important for solving problems with automation rules.  I recommend posting an image of your entire rule, images of any relevant actions / conditions / branches, and an image of the audit log details showing the rule execution.  Together those may help explain a symptom.

Next thing, what is the type of your field?  Is it text, single-select, multi-select, etc.?  The type of field can have an impact on the behavior of the match() function.

Next, what are the contents of your field, if it is text?  Specifically, does it have any newlines, bullets, etc.?  If so, that can impact the behavior of match.  The work-around for that is to add a split on newlines immediately prior to the match call, with split("\n")

Finally, and perhaps most importantly for your scenario: the match function documentation states that the regular expression parsing is based upon the Java Pattern class.  But it does not state what is / is not supported.  You may find several community posts where a regular expression worked elsewhere but not in an automation rule.  My recommendation is to use the simplest expression that could work, and test thoroughly.  And if that still does not work, revert to simple text functions and variables, as needed.

Kind regards,
Bill

Milena Prieto October 26, 2023

Thank you for your help!
I followed your suggestion to try new regex, and this time, I tried one from Atlassian, which initially didn't work for my case. However, I made some adaptations and finally managed to make it work:

((?<!([A-Z]+)-?)[A-Z]+-\d+)

Grateful for the assistance!

Like Bill Sheboy likes this
Elodie Ferreira February 19, 2025

Hi @Bill Sheboy
I'm having a similar issue with a regex to validate if the labels belong to a close set of options.
The rule I have is to send an email to the issue reporter if the labels change to values not allowed in the regex. Problem is, everytime I change that field, even if the current labels are allowed by the regex, the rule is triggered.


Elodie Ferreira February 19, 2025

image.png

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 19, 2025

Hi @Elodie Ferreira -- Welcome to the Atlassian Community!

As this is a very old thread, I recommend creating a new question.  That will ensure the maximum number of people see it to offer suggestions.

When you post your question, please include:

  • an image of the complete rule in one image for continuity
  • an image of the audit log details for the rule execution with all areas expanded
  • the full regular expression you are using for that condition, posted as plain text

Until we see your question...I recommend splitting up the regular expression and using it to test the labels, writing the results to the audit log.  That will confirm if one specific set of tokens in the expression is not matching.

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events