Forums

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

Regex in automation problems

daniel.jones
Contributor
November 6, 2025

Hello, really stumped.

I am on Data Center version 10.3.12

 

Long story short, I have need to extract a partial string from a set of text from a webhook.  I am trying to use native automation vs. Scriptrunner due to some organizational limitations.

I have tried various regex options but apparently DC does not support a lot of them like match and extract.  Also, I know JIRA stores variables as strings and you have to convert them to numbers.

So what I was able to do is get the index of the start of the string I want to extract, stored that as a variable, then figured I can use the index value plus notation to get the next 5 characters that I want.  But I am still having issues.

I am debugging by writing to the log, but while the automation does not fail or error, nothing is getting writing to the log.  It seems the asNumber may not be working either.

It is probably a brain cramp on my end with a simple fix, but I am not able to see it.

JIRAproblems.png

2 answers

1 accepted

0 votes
Answer accepted
Rudy Holtkamp
Community Champion
November 6, 2025

Hi @daniel.jones ,

Could you post an example of the data and an example of what you want to extract?

 

daniel.jones
Contributor
November 6, 2025

HI @Rudy Holtkamp 

the string will look like this

[Feature][MATRIX][Code 2025.4.5][ABC-62088] Migration Service – CI/CD Setup for EU

 

I need to get the JIRA key, ABC-62088.  or at least the 5 digit number from that

daniel.jones
Contributor
November 6, 2025

also, if it helps, the variable dashIndex is this

{{webhookData.pullRequest.title.indexOf("ABC-")}}

 

and issueTitle is this

{{webhookData.pullRequest.title}}

they both work and produce what is expected

 

Rudy Holtkamp
Community Champion
November 6, 2025

Ok, suppose you have the string you mentioned in a var called 'string'

string: [Feature][MATRIX][Code 2025.4.5][ABC-62088] Migration Service – CI/CD Setup for EU

Then you create a new var called myKey:

myKey: {{string.match("\[((?<!([A-Z]{1,10})-?)[A-Z]+-\d+)\]")}}

This will output ABC-62088, as you can see below. The regex will search for a Jira key within square brackets, so if another key is located in text at the end, you still get the correct key.

 

image.pngimage.png

daniel.jones
Contributor
November 7, 2025

@Rudy Holtkamp thanks for the suggestion.  I dont know if it is because I have Datacenter version or what, but match and extract dont work.  They always return empty and dont write to the log.

 

Rudy Holtkamp
Community Champion
November 9, 2025

Hi @daniel.jones ,

I don't know which version of DC you are using, but on 10.3.12, it works.

image.png

daniel.jones
Contributor
November 10, 2025

Thank you @Rudy Holtkamp  I had tried before, but maybe I goofed something up. I was able to get the info I wanted through a rather inelegant workaround.  So I have the key of the sub-task I want, but am having serious brain cramps now as I can not figure out how to get the action I want (transition, but just trying comment for debugging now) on that sub-task.  Since the trigger is a webhook there is no "trigger issue".  I tried to branch on JQL using the key I was able to extract (I also tried it with the key hard-coded to test) but the add comment action does nothing. 

hardCodedKey.png

Rudy Holtkamp
Community Champion
November 10, 2025

Try "Parent Link" instead of parent

image.png

daniel.jones
Contributor
November 10, 2025

@Rudy Holtkamp  see image below-nothing gets written to log

matchNoWork.png

daniel.jones
Contributor
November 10, 2025

@Rudy Holtkamp Parent Link wont work for sub-tasks, which is what I am looking for

Rudy Holtkamp
Community Champion
November 10, 2025

Strange, It did when I tried it on a Jira DC instance.

daniel.jones
Contributor
November 13, 2025

@Rudy Holtkamp I wanted to let you know that your post above where you recommended this

myKey: {{string.match("\[((?<!([A-Z]{1,10})-?)[A-Z]+-\d+)\]")}}

worked.

The reason it did not before was due to the way I had the webhook trigger set up.

So thank you! 

0 votes
daniel.jones
Contributor
November 7, 2025

Update-I gave up on match or extract, it seems they dont work in my Datacenter version? Glad if someone can prove me wrong.
But substring does work, so I updated my script.

I create a variable called keyStart with {{webhookData.pullRequest.title.indexOf("ABC-")}} and it produces the result desired.

Then I created a variable called keyEnd with {{#=}}{{webhookData.pullRequest.title.indexOf("ABC-")}} +9 {{/}}

This works as the key is always 9 digits-ABD then a dash, then 5 numbers

But when I try substring I am running into issues.  If I hard code with numbers it works, but there is not a defined start and end every time, it will vary.  So I wanted to use the variables for the start and end of the substring.

Works {{webhookData.pullRequest.title.substring(5,14)}} 

None of the below work

{{webhookData.pullRequest.title.substring(keyStart,keyEnd)}}

{{issueTitle.substring(keyStart.asNumber,keyEnd.asNumber)}}

{{webhookData.pullRequest.title.substring({{keyStart}},{{keyEnd}})}}

{{issueTitle.substring({{keyStart.asNumber}},{{keyEnd.asNumber}})}}

Rudy Holtkamp
Community Champion
November 9, 2025

These are never going to work:

{{webhookData.pullRequest.title.substring({{keyStart}},{{keyEnd}})}}

{{issueTitle.substring({{keyStart.asNumber}},{{keyEnd.asNumber}})}}

Within {{ }} you should not use {{ }} again. So the bold ones are not going to work.

But I guess you already knew that.

--

I don't know why, but sometimes it helps to create a var and then use the functions. So create a var called title with {{webhookData.pullRequest.title}}, then use
{{title.substring(keyStart.asNumber,keyEnd.asNumber)}}

 

Brian Eshult
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 25, 2025

@daniel.jones 
I was running into problems using regex functions in automation as well. Also in 10.3

I was able to get it to work by using a specific regex and variable formatting. Details here. Hope this is helpful for the future.

Like daniel.jones likes this

Suggest an answer

Log in or Sign up to answer