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.
Here's the smart value:
{{fields.customfield_10184.match("([A-Z]{2,}-\d+).*")}}
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
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.