Forums

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

Why is my Regex Match returning an array of results instead of one result?

gjuffer October 22, 2021

I've created an automation rule that scans the description of an incoming issue for an email address via a regex match, then adds a comment with that email address.  The automation is set up like this:

 

image.png

The code looks like this:

{{issue.description.match("([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)")}}

 

This automation successfully finds the email address and adds it to the comment, but it repeats the email twice with a comma separation, such as: 

example@address.com, example@address.com

It seems like the match function is returning an array.  How do I return only a singular email address?  

 

2 answers

1 accepted

3 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 22, 2021

Hi @gjuffer 

I hypothesize that is from how the email is put as markup in the description.  So if it is returning a list, you could get just one value by adding .first or .last to the end of that expression.

Kind regards,
Bill

gjuffer October 22, 2021

@Bill Sheboy thanks for the quick answer - I followed the link but am unsure if I'm using the correct syntax.  I tried the following code and it did not work:

{{issue.description.match.first("([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)")}}

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 22, 2021

Please move the first to the end; this makes it apply to the returned list from the match():

{{issue.description.match("([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)").first}}

Like • 2 people like this
gjuffer October 22, 2021

That totally works, thank you very much for your help @Bill Sheboy !

Like • Bill Sheboy likes this
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 22, 2021

Awesome; I am glad to learn that helped you.

__Bill

0 votes
gjuffer October 22, 2021

Well, I found a pretty useful video on Youtube from Ravi Sagar:

https://www.youtube.com/watch?v=jP90ckC29Kk

He suggested that you need to add .* before and after your regex.  This worked for me, but I can't say that I understand why.  The code that ended up working is as follows:

{{issue.description.match("(.*[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+.*)")}}

Fascinating.  Looks like I need to learn more.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events